remove needs a query at src/mongo/shell/collection.js

Run:

db.collectionname.remove({});

result :

WriteResult({ "nRemoved" : 7 })

As the message says you need to provide a query, but it can be an empty one (if you want to remove all documents):

db.messages.remove({})

EDIT: I would like emphasize the comment made by Stennie:

Note: if you actually want to remove all documents in a collection it is faster to a do a collection.drop(). The remove() operation will delete documents individually & update indexes as the documents are deleted; a drop() will immediately delete all documents & indexes for the collection.


If you are trying to drop the collection messages, then you need to execute db.messages.drop().

Otherwise, the command db.messages.remove() is used to delete a particular document and therefore you need to write a query to allow MongoDB engine to know which document needs to be gotten rid of. For ex. db.messages.remove({_id : }).

The lack of {_id : } is causing the error that remove needs a query....

Tags:

Mongodb