I am pretty new to MongoDb. However i am trying to implement below functionality using java.
I Have a document as below.
{
"_id" : ObjectId("like-001"),
"GroupID" : "1004",
"likedBy" : [
{
"personId" : 123,
"liked" : true
},
{
"personId" : 167,
"liked" : true
},
{
"personId" : 467,
"liked" : false
}
],
isdeleted:false
}
My functionality is, given a groupid, personId and Liked , find whether any document exist with given GroupId. If exist i should update that document with personId and Liked if the record not present, if person id also present I should not add the same person in array.
If the group id itself is not present I have to insert the entire document.
is there a way to do this with out making multiple calls to database. Also can this be done in bulk?