Update query in MongoDB shell
This is because in second parameter of update function you need to use $set operator to update location_country
as in example below:
db.checkin_4e95ae0926abe9ad28000001.update( {location_city:"New York"}, //find criteria // this row contains fix with $set oper { $set : { location_country: "FUDGE!"}});
Here you can find a list of available update operators.
Changed in version 3.6.Following is the syntax for update :
db.collection.update( <query>, <update>, { upsert: <boolean>, multi: <boolean>, writeConcern: <document>, collation: <document>, arrayFilters: [ <filterdocument1>, ... ] })
Example :
db.getCollection('products').update({},{$unset: {translate:1, qordoba_translation_version:1}}, {multi: true})
In your example :
db.checkin_4e95ae0926abe9ad28000001.update( {location_city:"New York"}, //query // $update query { $set : { location_country: "FUDGE!"}});
By default, the update() method updates a single document. Set the Multi Parameter to update all documents that match the query criteria.
Example 2 :
db.checkin_4e95ae0926abe9ad28000001.update( {location_city:"New York"}, //query // $update query { $set : { location_country: "FUDGE!"}}, {multi: true});
db.m_country.update( {"countryId": "962a0935-bf3d-4f63-a53c-254760273ede"}, {$set: {'countryPopulation': '12540000'}})