• Post Reply Bookmark Topic Watch Topic
  • New Topic

Update MongoDb sub document which is in a array  RSS feed

 
Kala Saseendran
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?



 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!