I accidentally created two databases with the same name. When I do show dbs
in my Mongo shell, I get this:
> show dbs
admin (empty)
local 0.078GB
Wes Widner answer is correct in that you most likely have a non-printable character. However, rather than remove the files from the filesystem directly, I prefer a more programmatic approach. They key here is to never really call the database by its literal name, but instead keep a reference to the name in variable form:
getSiblingDB
to each of them).db.dropDatabase
use bogus;
db.createCollection('blah');
db.getCollectionNames(); // [ "blah", "system.indexes" ]
use admin;
db.adminCommand({listDatabases:1}).databases.filter(function(d){
return d.name === 'bogus';
}).map(function(d){
return d.name;
}); // [ "bogus" ]
// use [0] here since we now 'bogus' was at index 0 in previous
// getSiblingDB will allow us to issue dropDatabase on the string
// representation of the database
db.getSiblingDB(db.adminCommand({listDatabases:1}).databases.filter(function(d){
return d.name === 'bogus';
}).map(function(d){
return d.name;
})[0]).dropDatabase();
Instead of specifically filtering by name
, we want to filter by sizeOnDisk
. Be sure not to select "admin" here, so run the adminCommand
with the filter/map first to get the applicable index. Chances are "admin" will be at index 0, so your database in question will most likely be at index 1:
db.getSiblingDB(db.adminCommand({listDatabases:1}).databases.filter(function(d){
return !d.sizeOnDisk;
}).map(function(d){
return d.name;
})[1]).dropDatabase(); // note usage of [1] here