I'm doing development on MongoDB. For totally non-evil purposes, I sometimes want to blow away everything in a database—that is, to delete every single collection, and whatever else might be lying around, and start from scratch. Is there a single line of code that will let me do this? Bonus points for giving both a MongoDB console method and a MongoDB Ruby driver method.
Join Stack Overflow to learn, share knowledge, and build your career.
|
|
|
|
|||||||||||||||||||||
|
|
Also, from the command line:
|
|||||
|
|
I had the same problem, when I needed to reset all the collections but didn't want to loose any database users. Use the following line of code, if you would like to save the user configuration for the database:
This code will go through all collection names from one database and drop those which do not start with "system.". |
|||||||||||||||||||||
|
|
I followed the
In my case I was running this from the command-line using:
|
|||||||||||||||||
|
|
By compiling answers from @Robse and @DanH (kudos!), I've got the following solution which completely satisfies me:
Connect to you database, run the code. It cleans the database by dropping the user collections and emptying the system collections. |
|||||
|
|
Use
|
||||
|
|
|
Hear are some use full delete operations for mongodb using mongo shell To delete particular document in collections: To delete all documents in collections: To delete collection : to delete database :
first go to that database by
|
||||
|
|
|
if you want to delete only a database and its sub-collections use this :
if you want to delete all the databases in mongo then use this :
|
|||||
|
|
Simplest way to delete a database say blog:
|
|||
|
|
|
For Meteor developers.
For everybody else.
|
|||
|
|
|
To delete all DBs use:
|
||||
|
|
MongoDB db.dropDatabase() documentation explaining the modification introduced in 2.6:
|
|||
|
|
Hope that helps |
|||
|
|
protected by user3100115 Oct 25 '16 at 5:29
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?