2

All I want is to update the value of the field "done" to "true"

I m developping with nodejs

here is the document :

{
"_id" : ObjectId("5a730e55114dbc2a0455c630"),
"email" : "[email protected]",
"password" : "12356789",
"tasks" : [ 
    {
        "title" : "new to do ",
        "description" : "new something ",
        "date" : "2018-02-07T18:16:29.469Z",
        "done" : false
    }, 
    {
        "title" : "new to d odo ",
        "description" : "dod ododoododododo",
        "date" : "2018-02-07T18:25:14.881Z",
        "done" : false
    }
]
}
6
  • You want to update it for some specific element or for each element in array? Commented Feb 8, 2018 at 11:36
  • a specific element for example the second one with the title "new to d odo " I want to change done to "true" Commented Feb 8, 2018 at 12:20
  • You could try using the $set operator: docs.mongodb.com/manual/reference/operator/update/set Commented Feb 8, 2018 at 13:44
  • can you tell a little bit more ? you want to change an object in nodejs , or in mongodb ? Commented Feb 8, 2018 at 19:00
  • I'm Sorry that the question wasn't clear for you ! I want to update the field "done" in the task named "new to d odo " in the array "tasks" in the hole object with nodeJS I'm asking for the querry because this document is from a MongoDb Database. Commented Feb 8, 2018 at 21:25

2 Answers 2

5

Something like this should work:

db.collectionName.update({
     "tasks.title": "new to d odo "
}, {
    $set: { "tasks.$.done": true }
})

You can check more details in the documentation.

Sign up to request clarification or add additional context in comments.

Comments

0

you can use

$push

$set

$addToSet

you can use these operators to insert any object or any value to an array in the mongoose model.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.