Mongo Update $ set not working

I am trying to update some mongo docs.

I am using a request

db.articles.update( { 'categories.id': ObjectId("51cd5272222wb6zs464fa4d9"), 'source.importer': 'pa' }, { $set : { 'source.expires-at': ISODate("2014-01-01T08:39:45Z") } } ) 

This request does not update the source.expires-at field, however, where the part of the instruction works fine.

Document structure

 { "_id": ObjectId("5211dc100000044707000015"), "categories": { "0": { "id": ObjectId("51cd5272222wb6zs464fa4d9") } }, "source": { "importer": "pa", "expires-at": ISODate("2013-09-18T08:49:32.0Z") } } 
+7
mongodb
source share
1 answer

Try the following:

 db.articles.update({ 'categories.id': ObjectId("51cd5272222wb6zs464fa4d9"), 'source.importer': 'pa'}, { $set : { 'source.expires-at': ISODate("2014-01-01T08:39:45Z") } }, {multi: true}) 

You will need to pass an additional argument to the {multi: true} parameter;

Take a look at https://education.10gen.com/courses/10gen/M101JS/2013_August/courseware/CRUD/Multi-update/

+13
source share

All Articles