Thursday 28 July 2016

DELETE in MongoDB

In our last post, we saw how one can use update statement in MongoDB. In this tutorial, we're going see how to delete/remove a document from MongoDB collection, how to delete/drop a collection and how to drop a database inside MongoDB.

deleteOne :

If you want to remove any one of the documents from the collection, then we can use MongoDB deleteOne command. It will just removes/deletes the specified document from collection. Let's the example now.

First, let's see what are all collections we have inside our db.









Now, we're going to remove/delete one document from "names" collection where _id:4.











Similarly, we can use deleteMany command to delete more than one document in MongoDB collection.

deleteMany :

DeleteMany command is used to delete multiple documents from the collection, where as deleteOne command is used to delete only one specified document from the collection.

Let's see one example on deleteMany.











See, in the above "names" collection is having 4 documents, we have just removed 2 documents from the collection where name:"John".


drop :

This command is used to drop the entire collection from the database including indexes.

Before drop :


After drop :


Here we just dropped "names" collection from the db using drop command in MongoDB.

dropDatabase :

To drop the entire database, you can consider using dropDatabase command.

First, let's how many dbs we have inside our server.


Now, let's drop the "zips" database using dropDatabase command.



Next Post : MongoDB schema design




6 comments:

  1. It has provided us the enough information within a relevant period of time ,the articles are encouraging the readers and building inspiration and motivation towards the topic,Your post is helpful to avoid the mistakes.Thanks so much for a detailed post!Hope you will keep on sharing articles.


    TECHNO DATA GROUP

    ReplyDelete
  2. Great site and a great topic as well I really get amazed to read this.It was very interesting and meaningful.
    Its an Important topic.
    oracle training in chennai

    oracle training institute in chennai

    oracle training in bangalore

    oracle training in hyderabad

    oracle training

    hadoop training in chennai

    hadoop training in bangalore

    keep posting such useful information.

    ReplyDelete
  3. This is the exact information I am been searching for, Thanks for sharing the required infos with the clear update and required points. To appreciate this I like to share some useful information.
    Its really helpful for the users of this site. I am also searching about these type of sites now a days.

    ReplyDelete
  4. This is the exact information I am been searching for, Thanks for sharing the required infos with the clear update and required points. To appreciate this I like to share some useful information

    Mongodb Training in Bangalore

    ReplyDelete
  5. Free download EaseUs Data Recovery Wizard pro v15 windows pc · Must disable internet connection & Antivirus · Extract the file using the latest Winrar · Process .Easeus Data Recovery 14.5 Crack

    ReplyDelete