I have an object structure like this:
{
"_id" : ObjectId("4faaba123412d654fe83hg876"),
"user_id" : 123456,
"total" : 100,
"courses" : [
{
name: 'tech',
data: [
{ active: false, blabla: []},
{ active: false, blabla: []},
{ active: true /*change to false*/, blabla: [/* add item here*/]}
]
}
]
}
and my goal is to update those two fields active and push something inside the blabla array. Those things are nested inside the data array.
My attempt was to filter through the course names that has tech as a value ( which is also a goal ), find active = true, and do the update.
Here is the code:
db.getCollection('users').update({
"courses.name" : 'tech',
"courses.data.active" : true
}, {$set : {"courses.$.data.active" : false}}, {$push : {"courses.$.data.blabla": 1}})
What I got is:
Cannot create field 'active' in element {data: [ { active: ...
and what I want to achieve is:
data: [
{ active: false, blabla: []},
{ active: false, blabla: []},
{ active: FALSE , blabla: [1]}
]
I am using version 4.0.2 of Mongodb.