Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (47.6k points)

In the shell, my query is:

db.checkin_4e95ae0926abe9ad28000001.update({location_city:"New York"}, {location_country: "FUDGE!"});

However, it doesn't actually update my records. It doesn't error either. When I do a db.checkin_4e95ae0926abe9ad28000001.find({location_city:"New York"}); after running this, I get all my results but the location_country has not changed:

"_id": ObjectId("4e970209a0290b70660009e9"), 

"addedOn": ISODate("2011-10-13T15:21:45.772Z"),

"location_address1": "", 

"location_city": "New York", 

"location_country": "United States", 

"location_latLong": { 

"xLon": -74.007124, 

"yLat": 40.71455 

}, 

"location_source": "socialprofile", 

"location_state": "New York", 

"location_zip": "" 

}

2 Answers

0 votes
by (106k points)

To update query in MongoDB shell you need to change the version to 3.6. Following is the syntax for update :

db.collection.update( 

<query>, 

<update>, 

upsert: <boolean>, 

multi: <boolean>, 

writeConcern: <document>, 

collation: <document>, 

arrayFilters: [ <filterdocument1>, ... ] 

)

0 votes
by (108k points)

This is because in the second parameter of update function you need to use $set operator to update location_country as in the example below:

db.checkin_4e95ae0926abe9ad28000001.update(

   {location_city:"New York"}, //find criteria

   // this row contains fix with $set oper

   { $set : { location_country: "FUDGE!"}});

Related questions

0 votes
2 answers
0 votes
2 answers
0 votes
1 answer
0 votes
2 answers

Browse Categories

...