Reputation: 1262
Here is the schema:
var user = new Schema ({
name: {type:String},
lastName: {type:String},
extraInfo: {
phone: {type:String},
age: {type: Number}
},
postalCode: {type:Number}
})
Let's assume we have 10 documents with that schema and 5 of them have postalCode '12345'.
How can I select all of them and update the extraInfo.phone and extraInfo.age of these documents?
Upvotes: 1
Views: 1010
Reputation: 3753
Well, i dont have a database at hand, to try it out, but it should be something like this.
db.User.update(
{postalCode: 12345},
{"extraInfo.phone": value1, "extraInfo.age": value2},
{multi: true});
Upvotes: 2