Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-2384

remove({_id : undefined}); removes everything from collection

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Fixed
    • Affects Version/s: 1.6.5
    • Fix Version/s: 1.7.5
    • Component/s: Querying, Shell, Usability
    • Labels:
      None
    • Operating System:
      ALL

      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.

        Attachments

          Activity

            People

            Assignee:
            eliot Eliot Horowitz (Inactive)
            Reporter:
            garo Juho Mäkinen
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: