Reputation: 2351
I have a authenticated user with all required privileges to drop a database. I want to drop the database from the shell and tried following command
mongo -uuser -ppass newdb --eval "db.dropDatabase();"
I got following:-
MongoDB shell version: 2.4.9
connecting to: newdb
[object Object]
That's it I got no errors and no results. The database still exists with all values.
Upvotes: 4
Views: 4341
Reputation: 9080
Your command should work
mongo -uuser -ppass newdb --eval "db.dropDatabase();"
If you access to mongo after that with
mongo -uuser -ppass newdb
The database is created again but empty, so when you said:
The database still exists with all values.
Are you sure that has all collections inside ?
To check if has been deleted you can do:
mongo -uuser -ppass
> show dbs
The "newdb" shouldn't appear.
I've tested it with Mongo 2.4.2.
Upvotes: 2
Reputation: 3937
You may try this:
mongo -u USER -p PASS --eval "db=db.getSiblingDB('DB_NAME');db.dropDatabase();"
Reference: http://docs.mongodb.org/manual/tutorial/write-scripts-for-the-mongo-shell/
Upvotes: 1