RoboMongo - Cannot Remove Documents from Collection

5.6k views Asked by At

I'm using RoboMongo to delete a number of documents that match a query. However, it is saying no documents have been delete with the following:

db.getCollection('assets').remove( { "source": "red" } );        

However, this works perfectly:

db.getCollection('assets').find( { "source": "red" } );  

and displays all the records with the source "red".

Is there any reason why the records are not being removed and robomongo is just outputting 0?

Kind Regards,

5

There are 5 answers

0
Manthan Upadhyay On

You can try this one:

db.assets.remove( {source : "red" } ) 
0
Mital Gajjar On

You can try this query:

db.assets.remove( { "source":"red"} )
0
Christine On

Try removing the double quotes around the field name and try something like this:

db.getCollection('assets').remove( { source: "red" } ); 
0
Gabriel On

Are you running with a replica set? If so make sure that you are running the remove command on the primary node.

0
Theophilus Omoregbee On

DeleteMany worked for me: https://docs.mongodb.com/v3.2/reference/method/db.collection.deleteMany/#db.collection.deleteMany

db.getCollection('assets').deleteMany({source: 'red'})

This should return

/* 1 */
{
    "acknowledged" : true,
    "deletedCount" : number // which is the number of documents deleted
}

example screenshot

From the above query, I removed all passengers that the snapshot id is 5c749daee3a0ec00047ffd5c