MongoDB extra Collections
The mysterious 2 collections
There are two collections created when a user stores data in a database for the first time or a database is created explicitly.
The first one, system.indexes
holds the information about the indices defined in the various collections of the database. You can even access it using
db.system.indexes.find()
The hidden one, system.namespaces
holds some metadata about the database, actually the name of all existing entities from the point of view of the database management.
Although it is not shown, you can still access it:
db.system.namespaces.find()
Warning: Don't fiddle with either of them. Your database may well become unusable. You have been warned!
There can be even more than those two. Read System Collections in the MongoDB docs for details.
The mysterious 4 objects
Actually, If you have tried to access the system databases as shown above, this one becomes very easy. In a database called foobardb
with a collection foo
and the default index on _id
, querying system.indexes
will give a result like this (prettified):
{ "v" : 1, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "foobardb.foo"}
Note that this is a single document. The prettified output of the second query looks like this:
{ "name" : "foobardb.foo" }{ "name" : "foobardb.system.indexes" }{ "name" : "foobardb.foo.$_id_" }
Here, we have three documents. So we have 4 additional documents inside the metadata.