Derek Smith
Derek Smith

Reputation: 231

MongoDB Drop Database With Invalid Name

I somehow ended up with a database named "*" on my mongo server. I want to get rid of it, but I can't find a way to drop it. Trying to execute the normal dropDatabase() functions don't work because the shell won't let me select it (i.e. I run "use *").

How can I drop this database? I tried things like db.getSiblingDB("*").dropDatabase();

Any ideas?

Upvotes: 1

Views: 1024

Answers (2)

Yang C
Yang C

Reputation: 536

What I had succeed switch to the database whose name contains "invalid" letters is to open the CMD in Windows and redirect to the mongodb /bin folder, and then open "mongo.exe" using command line with the database name u wanna switch to as the parameter. So here we go!


EX: Open database named "Congrès"

c:\Program Files\mongodb\bin>mongo.exe Congrès

Upvotes: 0

Chien-Wei Huang
Chien-Wei Huang

Reputation: 1861

I can drop it.

MongoDB shell version: 2.2.0
connecting to: test
> use *
switched to db *
> db.test.insert({'t':1})    
> show tables    
system.indexes    
test
> show dbs;
*       0.203125GB
admin   0.203125GB
local   (empty)
> use *
switched to db *
> db.dropDatabase()
{ "dropped" : "*", "ok" : 1 }
> show dbs;
admin   0.203125GB
local   (empty)

Upvotes: 1

Related Questions