I generated a database test
in MongoDB, having a collections named col
. The command show dbs
gives:
admin (empty)
local 0.078GB
test 1.953GB
(I really don't know, why the size is >1.9 GB, since there is only 21 small documents in the collection col
).
The Command db.stats()
tells me, that there are 3 collections available:
{
"db" : "test",
"collections" : 3,
"objects" : 25,
"avgObjSize" : 96.64,
"dataSize" : 2416,
"storageSize" : 857456640,
"numExtents" : 19,
"indexes" : 1,
"indexSize" : 8176,
"fileSize" : 2080374784,
"nsSizeMB" : 16,
"dataFileVersion" : {
"major" : 4,
"minor" : 5
},
"extentFreeList" : {
"num" : 2,
"totalSize" : 139264
},
"ok" : 1
}
But when i type show collections
, only two collections are listet.
col
system.indexes
So, where does this 3rd collection come from?
And does it explain why the test-Database is 1.9GB large? db.col.stats()
tells me, that lots of data is stored, but the 21 documents are really small:
{
"ns" : "test.col",
"count" : 21,
"size" : 2160,
"avgObjSize" : 102,
"storageSize" : 857440256,
"numExtents" : 17,
"nindexes" : 1,
"lastExtentSize" : 227803136,
"paddingFactor" : 1,
"systemFlags" : 1,
"userFlags" : 1,
"totalIndexSize" : 8176,
"indexSizes" : {
"_id_" : 8176
},
"ok" : 1
}
The size
Ok, first, as for the size:
show dbs
shows the size of the actual data files, not their content.MongoDB preallocates datafiles of static size, usually beginning with 64MB (+ a namespace file), doubling which each step until 2GB are reached. Each subsequent datafile will have 2GB in size. A new datafile is allocated as soon as the last allocated datafile receives it's first entry, thereby eliminating latency for data file allocation for requests.
It may well be the case that your test database (being the default database) was much bigger, but documents or even whole collections were deleted. However, as of the time of this writing, mongod never reclaims disk space automatically, but leaves allocated datafiles for future use.
The "Ghost" collection
As for the "Ghost" collection: Yes, there is one. It is the namespace collection of the database (not surprisingly called
system.namespaces
), which is implicit. Have a look at the output ofThat being said: Don't fiddle with any of the
system.*
collections. They don't have their name for fun.