Reputation: 34513
when we run the show dbs
command, the x-development
database doesn't appear. then when we drop the database from the shell, it still allows us to access it again:
> use x-development
switched to db x-development
> db.dropDatabase()
{ "dropped" : "x-development", "ok" : 1 }
> use x-development
switched to db x-development
>
why is this happening? we're on mongo 2.2.
we're trying to drop the database because it appears under mongostat
, and we want to make sure this database isn't taking server resources:
[root@mongo]# mongostat
connected to: 127.0.0.1
insert query update delete getmore command flushes mapped vsize res faults locked db idx miss % qr|qw ar|aw netIn netOut conn time
0 5 0 0 0 1 1 2.11g 4.86g 464m 0 x-development:0.0% 0 0|0 0|0 62b 2k 3 11:42:57
0 0 0 0 0 1 0 2.11g 4.86g 464m 0 x-development:0.0% 0 0|0 0|0 62b 2k 3 11:42:58
0 0 0 0 0 1 0 2.11g 4.86g 464m 0 x-development:0.0% 0 0|0 0|0 62b 2k 3 11:42:59
so the real question is: why is this database appearing under mongostat
if the database doesn't exist?
Upvotes: 1
Views: 2586
Reputation: 13616
In Mongo you don't create databases explicitly. You just start using it (for example by issuing a use
statement) and it gets created automatically.
The database won't be using any resources if you don't query it. So, I don't think you should worry about it.
Upvotes: 0
Reputation: 180917
> db.dropDatabase()
...indeed drops the database. use
can switch to any database, existing or not, it's not until you actually insert something that the database is recreated.
> show dbs
local (empty)> use dev
switched to db dev> show dbs
local (empty)> db.test.insert({a:1})
> show dbs
dev 0.203125GB
local (empty)> db.dropDatabase()
{ "dropped" : "dev", "ok" : 1 }> show dbs
local (empty)
Upvotes: 3