MongoDB: unconditional updates? -


this seems silly question haven't yet found answer. if wanted add same field->value every record in mongodb collection, appropriate shell command so? tried doing multi update blank query ({}) resulted in error:

multi update works $ operators

i'm bit puzzled how around this. suggestions?

the error says all: can modify multiple documents using $ modifier operators. had this:

> db.coll.update({ }, { a: 'b' }, false, true); 

which replace first object in collection { a: 'b' } if multi false. wouldn't want replace objects in collection same document!

use $set operator instead:

> db.coll.update({ }, { '$set': { a: 'b' } }, false, true); 

this set a property of every document (creating necessary) 'b'.


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -