Multi-update does not work in MongoDB

I have a collection that I filled out from CSV, but there are several fields that I no longer need in the record, so I want to delete them, but it seems to do nothing, 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?

+4
source share
3 answers

Your syntax is incorrect. The upgrade operation in the CLI for versions to version 2.2 is as follows:

update (criteria, update, upsert, several )

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 use is valid for the latest stable version of mongod.

+18
source

I had the same problem using the native node driver.

{multi:1} does not work

{multi:true} does

This is strange

0
source

Please try as follows:

The CLI for versions above 2.0 is as follows:

update (criteria, update, update, several)

Example:

db.collectionname.update ({condition}, {$ set: {groupid: '541ae260514ca0b76981222f'}}, false, {multi: true});

0
source

All Articles