Prayas Agrawal
Prayas Agrawal

Reputation: 161

pushing data inside a list of a object in mongo

i want to push data to a list inside a document along with updating some other keys.

one document in db:

{
   "_id":"1",
   "name" : "prayas Agrawal",
   "abc" :{
        "is_completed":false, 
        "status":"failed",
        "message": ["xyz"]
   } 
}

this is my document structure

and i want to make the status:"pass", "is_completed": true and push a message in message "succes at 20:12"

Upvotes: 0

Views: 103

Answers (1)

Gibbs
Gibbs

Reputation: 22974

db.test.update({ //Find 
  
},
{
  $set: {//update
    "abc.is_completed": true,
    "abc.status": "pass"
  },
  $push: {//push
    "abc.message": "succes at 20:12"
  }
})

Upvotes: 1

Related Questions