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




21 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
  6. Great post! The information was really helpful and easy to understand. Looking forward to more content like this.
    mongodb classes

    ReplyDelete
  7. This blog is very informative. I learned something new today—thanks for sharing!
    mongodb course

    ReplyDelete
  8. Amazing article! The way you explained the topic is very clear and well-structured.
    mongodb full course

    ReplyDelete
  9. I really enjoyed reading this. Keep up the good work and continue posting valuable content.
    mongodb learning path

    ReplyDelete
  10. Thanks for the detailed explanation! It really helped me understand the concept better.
    mongodb training

    ReplyDelete
  11. Very useful content. I appreciate the effort you put into writing this blog.
    mongodb training online

    ReplyDelete
  12. Excellent insights! I will definitely apply these tips in my work.
    mongodb online course

    ReplyDelete
  13. Great writing style—simple, clear, and engaging. Waiting for your next post!
    best mongodb online course

    ReplyDelete
  14. This was a really helpful article. Thanks for breaking it down so well.
    mongodb certification course

    ReplyDelete
  15. Loved this post! Your content always adds value and helps readers learn easily.
    best mongodb course

    ReplyDelete
  16. Great post! The information was really helpful and easy to understand. Looking forward to more content like this.
    mongodb administration course

    ReplyDelete
  17. This blog is very informative. I learned something new today—thanks for sharing!
    mongodb dba course

    ReplyDelete
  18. Amazing article! The way you explained the topic is very clear and well-structured.
    mongodb learn online

    ReplyDelete
  19. I really enjoyed reading this. Keep up the good work and continue posting valuable content.
    mongodb online classes

    ReplyDelete
  20. Thanks for the detailed explanation! It really helped me understand the concept better.
    mongodb dba online training

    ReplyDelete