patternMinor
mongodb: drop all collections
Viewed 0 times
dropmongodbcollectionsall
Problem
How to remove existing content before entering a replicaset the first time?
mongodb worries about:
... has data already, cannot initiate set. All members except initiator must be empty.
mongodb worries about:
... has data already, cannot initiate set. All members except initiator must be empty.
Solution
db.dropDatabase() will drop the database, which will also drop all of the collections within a database.If you need to see what databases you have, you can do
show dbs.Update: Here's a script to delete everything, make sure you really want to do this:
var dbs = db.getSisterDB('admin').adminCommand("listDatabases").databases
for(d in dbs) db.getSisterDB(dbs[d].name).dropDatabase();Code Snippets
var dbs = db.getSisterDB('admin').adminCommand("listDatabases").databases
for(d in dbs) db.getSisterDB(dbs[d].name).dropDatabase();Context
StackExchange Database Administrators Q#20104, answer score: 4
Revisions (0)
No revisions yet.