I'm trying to do something with Mongo but I'm stuck. I'm certain the answer is super easy but I can't find it out. Thank you very much for your help.
I have a document (see below) I want to update.
{
_id: ObjectId("57d52d9c56f0dc1c93254265"),
processus: [
{
action: "action 1",
date: ISODate("2016-08-23T22:00:00Z")
},
{
action: "action 2",
date: ISODate("2016-12-11T23:00:00Z")
}
]
}
More precisely, I want to "change the date" of action 1. For example, I want to make my document like this:
{
_id: ObjectId("57d52d9c56f0dc1c93254265"),
processus: [
{
action: "action 1",
date: "another date"
},
{
action: "action 2",
date: ISODate("2016-12-11T23:00:00Z")
}
]
}
Below my update statement (which doesn't work / same thing with $push)
db.collection('...').update(
{ _id : ObjectId(...) },
{ $addToSet: {
processus: {
$each: [ { "action" : "action 1", "date" : "another date" } ],
}
}}
)
Indeed, the resulting document is:
{
_id: ObjectId("57d52d9c56f0dc1c93254265"),
processus: [
{
action: "action 1",
date: "another date"
},
{
action: "action 1",
date: ISODate("2016-08-23T22:00:00Z")
},
{
action: "action 2",
date: ISODate("2016-12-11T23:00:00Z")
}
]
}
Any idea? Thanks again.