Multi update not working in MongoDB

mongodb

Solution

Your syntax is not correct. The update operation in the CLI for versions before 2.2 looks as follows :

update(criteria, update, upsert, multiple)

When corrected it works :

> db.stops.update({}, { $unset: {stop_lat: 1, stop_lon: 1} }, false, true)
> db.stops.findOne({stop_id: 1000})
{ "_id" : ObjectId("50d30386884be8bf2a6c208a"), "stop_id" : 1000 }

EDIT : As Sammaye points out the syntax you're using is valid on the latest stable version of mongod.

Problem

I have a collection which I've populated from a CSV, however there are a few fields I don't need any more in the record, so I want to remove them, but it doesn't appear to be doing anything. This is from the CLI: ``` > db.stops.update({}, { $unset: {stop_lat: 1, stop_lon: 1} }, { multi: 1 }) > db.stops.findOne({stop_id: 1000}) { "_id" : ObjectId("50d30386884be8bf2a6c208a"), "stop_id" : 1000, // some other fields "stop_lat" : -27.339115, "stop_lon" : 153.043884, } ``` What am I doing wrong here?

Original source