I have a db called index having only one collection named student.
When I fire query db.students.find({}).count()
It shows 1000000 docs in it.
But when I used db.stats() It shows result like:-
{
"db" : "index",
"collections" : 3,
"objects" : 1000004,
"avgObjSize" : 59.95997216011136,
"dataSize" : 59960212,
"storageSize" : 87420928,
"numExtents" : 14,
"indexes" : 1,
"indexSize" : 32458720,
"fileSize" : 520093696,
"nsSizeMB" : 16,
"ok" : 1
}
3 collections how ?
No of object 1000004 which is 4 extra from expected ?
And finally i did db.getCollectionNames()
it shows [ "student", "system.indexes" ]
What is system.indexes
?
Please anybody elaborate on it?
I am new to the world of mongo.
As mentioned above, a single database can have multiple collections. The following creates multiple collections. Use the show collections commands to list all the collections in a database.
In general, we recommend limiting collections to 10,000 per replica set. When users begin exceeding 10,000 collections, they typically see decreases in performance. To avoid this anti-pattern, examine your database and remove unnecessary collections.
Working with MongoDB and ElasticSearch is an accurate decision to process millions of records in real-time. These structures and concepts could be applied to larger datasets and will work extremely well too.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With