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
Commits
f346a584
Commit
f346a584
authored
2 years ago
by
Prajwal Patil
Browse files
Options
Downloads
Patches
Plain Diff
#9
Added the arrayfilter and upsert option in separate customeUpdate function
parent
f9566fde
Branches
PP_ARRAYFILTER_NEW_CHANGE
1 merge request
!249
#9 Added the arrayfilter and upsert option in separate customeUpdate function
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
dalmdl/coremongo/coremongo.go
+42
-0
dalmdl/coremongo/coremongo.go
with
42 additions
and
0 deletions
dalmdl/coremongo/coremongo.go
+
42
−
0
View file @
f346a584
...
...
@@ -515,6 +515,48 @@ func (mg *MongoDAO) PushData(selector map[string]interface{}, data interface{})
return
nil
}
//custom update with extra options
func
(
mg
*
MongoDAO
)
CustomUpdateWithOptions
(
selector
map
[
string
]
interface
{},
data
interface
{},
updateOps
map
[
string
]
interface
{})
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
{}
resMarshal
,
err
:=
json
.
Marshal
(
updateOps
)
if
err
!=
nil
{
return
errormdl
.
Wrap
(
"cannot marshal:"
)
}
obj
:=
gjson
.
ParseBytes
(
resMarshal
)
loggermdl
.
LogError
(
obj
)
if
updateOps
!=
nil
{
if
obj
.
Get
(
"arrayFilter"
)
.
Value
()
!=
nil
{
arr
:=
obj
.
Get
(
"arrayFilter"
)
.
Value
()
.
([]
interface
{})
ops
.
SetArrayFilters
(
options
.
ArrayFilters
{
Filters
:
arr
,
})
}
if
obj
.
Get
(
"upsert"
)
.
Value
()
!=
nil
{
ops
.
SetUpsert
(
obj
.
Get
(
"upsert"
)
.
Bool
())
}
}
_
,
updateError
:=
collection
.
UpdateMany
(
context
.
Background
(),
selector
,
data
,
&
ops
)
if
errormdl
.
CheckErr1
(
updateError
)
!=
nil
{
return
errormdl
.
CheckErr1
(
updateError
)
}
return
nil
}
// CustomUpdate - CustomUpdate
func
(
mg
*
MongoDAO
)
CustomUpdate
(
selector
map
[
string
]
interface
{},
data
interface
{})
error
{
session
,
sessionError
:=
GetMongoConnection
(
mg
.
hostName
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets