[SERVER-2384] remove({_id : undefined}); removes everything from collection Created: 20/Jan/11  Updated: 12/Jul/16  Resolved: 21/Jan/11

Status: Closed
Project: Core Server
Component/s: Querying, Shell, Usability
Affects Version/s: 1.6.5
Fix Version/s: 1.7.5

Type: Bug Priority: Minor - P4
Reporter: Juho Mäkinen Assignee: Eliot Horowitz (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Participants:

 Description   

db.somecollection.remove({_id : undefined}); removes every item from the collection. I think that the correct behavior would be to throw an error.

Example:
db.temp.insert(

{ _id : 1}

);
db.temp.insert(

{ _id : 2}

);
db.temp.remove({_id : undefined});
db.temp.find(); // returns nothing

Same thing happens with any undefined property:

db.temp.insert(

{ _id : 1}

);
db.temp.insert(

{ _id : 2}

);
db.temp.remove(

{foo : undefined}

);
db.temp.find(); // returns nothing

I could easily imagine a situation where a code like this: db.users.remove({_id : user.id}); would be called with an user object which doesn't have id set, which would end up calling db.users.remove({_id : undefined}); and thus removing all users from the entire database.

I know that the programmer should have prevented this error, but I also believe that the database should be smart enough to prevent such disaster. After all, the programmer should be using .remove() without any additional parameters or just .drop() if he wants to erase the entire collection.



 Comments   
Comment by auto [ 21/Jan/11 ]

Author:

{u'login': u'erh', u'name': u'Eliot Horowitz', u'email': u'eliot@10gen.com'}

Message: remove(

{ x : undefined }

) should not delete everything in the collection SERVER-2384
https://github.com/mongodb/mongo/commit/c31c7f322943034bd294993e832f51383799ee5f

Generated at Thu Feb 08 02:59:48 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.