How to update an object in mongodb via mongoose?

I have a mongoose diagram like:

var Organization = new Schema({ name: String, address: { street : String, city: String } }, { collection: 'organization' }); 

How to update only the street part of the address for an organization through mongoose?

+7
mongodb mongoose
source share
1 answer

I cannot find any documents that cover this simple case, so I can understand why you have problems. But it's as simple as using $set with a key that uses dotted notation to refer to an inline field:

 OrganizationModel.update( {name: 'Koka'}, {$set: {'address.street': 'new street name'}}, callback); 
+9
source share

All Articles