I have the below document stored in mongo DB collection,I will need to add new subscribers For eg.,I need to add the subscriber with "protocol" : "SOAP" and url http://localhost.8080/FNOL/subscriber3 for the name "name" : "FNOL","country" : "US","lob" : "property" from the document.
If the url we are adding already exist we shouldn't add to the document,in case if the document does not exist with matching criteria name "name" : "FNOL","country" : "US","lob" : "property" i would need to insert a new document.
is it possible to do all the above in a single command in mongo db?
Thanks in advance.
{
"_id" : ObjectId("5b07fbbc0d7a677d2f8b2d87"),
"name" : "FNOL",
"country" : "US",
"lob" : "property",
"subscribers" : [
{
"protocol" : "REST",
"url" : "http://localhost.8080/FNOL/subscriber1"
},
{
"protocol" : "SOAP",
"url" : "http://localhost.8080/FNOL/subscriber2"
},
{
"protocol" : "JMS",
"url" : "NOTIFICATION.TOPIC.FNOL"
}
]
}
After updation:
{
"_id" : ObjectId("5b07fbbc0d7a677d2f8b2d87"),
"name" : "FNOL",
"country" : "US",
"lob" : "property",
"subscribers" : [
{
"protocol" : "SOAP",
"url" : "http://localhost.8080/FNOL/subscriber2"
},
{
"protocol" : "JMS",
"url" : "NOTIFICATION.TOPIC.FNOL"
},
{
"protocol" : "SOAP",
"url" : "http://localhost.8080/FNOL/subscriber2"
}
,
{
"protocol" : "SOAP",
"url" : "http://localhost.8080/FNOL/subscriber3"
}
]
}