I have an mongodb document like:
{
"name" : "JohnDoe",
"adds" : [
{
"status" : "PENDING",
"date" : "2015年09月23日"
},
{
"status" : "PENDING",
"date" : "2015年10月01日"
}
]
}
I want to update all the elements array like:
collection.update({'name':'JohnDoe'}, {'$set':{'adds.status':'APPROVED'}}).
How to do that?
EDIT: Most solution says to use positional operator to select the array element then use the operator to update that element. But In my case i have to update each element in array.
I have an mongodb document like:
{
"name" : "JohnDoe",
"adds" : [
{
"status" : "PENDING",
"date" : "2015年09月23日"
},
{
"status" : "PENDING",
"date" : "2015年10月01日"
}
]
}
I want to update all the elements array like:
collection.update({'name':'JohnDoe'}, {'$set':{'adds.status':'APPROVED'}}).
How to do that?
I have an mongodb document like:
{
"name" : "JohnDoe",
"adds" : [
{
"status" : "PENDING",
"date" : "2015年09月23日"
},
{
"status" : "PENDING",
"date" : "2015年10月01日"
}
]
}
I want to update all the elements array like:
collection.update({'name':'JohnDoe'}, {'$set':{'adds.status':'APPROVED'}}).
How to do that?
EDIT: Most solution says to use positional operator to select the array element then use the operator to update that element. But In my case i have to update each element in array.
Update all elements in an array in mongodb
I have an mongodb document like:
{
"name" : "JohnDoe",
"adds" : [
{
"status" : "PENDING",
"date" : "2015年09月23日"
},
{
"status" : "PENDING",
"date" : "2015年10月01日"
}
]
}
I want to update all the elements array like:
collection.update({'name':'JohnDoe'}, {'$set':{'adds.status':'APPROVED'}}).
How to do that?