4

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.

Roberto
  • 8,586
  • 3
  • 42
  • 53
bor
  • 2,211
  • 4
  • 22
  • 37
  • Currently you would be on the "test" database unless you specified something else to connect to. Also you don't state an error or what happened/didn't happen in your question. – Neil Lunn Mar 21 '14 at 06:41

2 Answers2

2

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.

Roberto
  • 8,586
  • 3
  • 42
  • 53
1

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/

ZZY
  • 3,689
  • 19
  • 22