mongoDB – remove a document

In mongoDB we can remove a document like in SQL. In mongoDb we use remove function to remove a document.

In remove function we specify some criteria that is like where clause in SQL

if we want to remove a document where name is mike the we will do it like this.

> db.users.remove({"name":"mike"});

 

If we donot specify any condition then all the documents in collection will be removed one by one.

> db.users.remove({});

If we have a large collection and we want to remove more efficiently then

> db.users.drop();

This command will drop whole collection.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.