Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Question

added 184 characters in body
Source Link
Manish Gupta
  • 4.7k
  • 19
  • 63
  • 111

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.

Source Link
Manish Gupta
  • 4.7k
  • 19
  • 63
  • 111

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?

lang-js

AltStyle によって変換されたページ (->オリジナル) /