Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
MKCLOS
Core Development Platform
corepkgv2
Merge requests
!231
Release v1.2.1
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Release v1.2.1
devbranch
into
staging
Overview
0
Commits
4
Pipelines
0
Changes
3
Merged
Akshay Bharambe
requested to merge
devbranch
into
staging
4 years ago
Overview
0
Commits
4
Pipelines
0
Changes
3
Expand
Add: Upsert ID in MongoDB upsert operation
Update: Send & Receive Message Size to 50 MB (previously this change was included in v1.1.3)
Edited
4 years ago
by
Akshay Bharambe
0
0
Merge request reports
Compare
staging
staging (base)
and
latest version
latest version
82d7ea7a
4 commits,
4 years ago
3 files
+
43
−
4
Expand all files
Preferences
File browser
List view
Tree view
Compare changes
Inline
Side-by-side
Show whitespace changes
Show one file at a time
Search (e.g. *.vue) (Ctrl+P)
dalmdl/coremongo/coremongo.go
+
35
−
2
Options
@@ -435,9 +435,40 @@ func (mg *MongoDAO) GetAggregateData(selector interface{}) (*gjson.Result, error
return
&
rs
,
nil
}
// UpsertWithID - will update or upsert a document in the collection
//
// If a new document is upserted then it will return the ObjectID (string) of the upserted document.
//
// If no document is upserted the object id returned will be empty string.
func
(
mg
*
MongoDAO
)
UpsertWithID
(
selector
map
[
string
]
interface
{},
data
interface
{})
(
string
,
error
)
{
session
,
sessionError
:=
GetMongoConnection
(
mg
.
hostName
)
if
errormdl
.
CheckErr
(
sessionError
)
!=
nil
{
return
""
,
errormdl
.
CheckErr
(
sessionError
)
}
if
mg
.
hostName
==
""
{
mg
.
hostName
=
defaultHost
}
db
,
ok
:=
config
[
mg
.
hostName
]
if
!
ok
{
return
""
,
errormdl
.
Wrap
(
"No_Configuration_Found_For_Host: "
+
mg
.
hostName
)
}
collection
:=
session
.
Database
(
db
.
Database
)
.
Collection
(
mg
.
collectionName
)
ops
:=
options
.
UpdateOptions
{}
ops
.
SetUpsert
(
true
)
upsertRes
,
updateError
:=
collection
.
UpdateOne
(
context
.
Background
(),
selector
,
bson
.
M
{
"$set"
:
data
},
&
ops
)
if
errormdl
.
CheckErr1
(
updateError
)
!=
nil
{
return
""
,
errormdl
.
CheckErr1
(
updateError
)
}
if
upsertRes
.
UpsertedID
!=
nil
{
return
getInsertedId
(
upsertRes
.
UpsertedID
),
nil
}
return
""
,
nil
}
// Upsert will update single entry
func
(
mg
*
MongoDAO
)
Upsert
(
selector
map
[
string
]
interface
{},
data
interface
{})
error
{
session
,
sessionError
:=
GetMongoConnection
(
mg
.
hostName
)
/*
session, sessionError := GetMongoConnection(mg.hostName)
if errormdl.CheckErr(sessionError) != nil {
return errormdl.CheckErr(sessionError)
}
@@ -456,7 +487,9 @@ func (mg *MongoDAO) Upsert(selector map[string]interface{}, data interface{}) er
if errormdl.CheckErr1(updateError) != nil {
return errormdl.CheckErr1(updateError)
}
return
nil
return nil */
_
,
err
:=
mg
.
UpsertWithID
(
selector
,
data
)
return
err
}
// PushData - append in array
Menu
Explore
Projects
Groups
Topics
Snippets