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.

1
  • 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. Commented Mar 21, 2014 at 6:41

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

6 Comments

what is uuser is it a typo of user ?
No, the first "u" is the command param -u , i.e: mongo -ujohn -pjohn_pass
using -u user is invalid ?
No, you can pass the param in both ways (with and without whie-space). I use this format in my answer because is the format used in the original question.
I just test both case it still throw authentication error when using with eval
|
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/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.