I have a mongodb with number of collections.
Eg:
--mongo_db (db name)
-- aa
-- bb
-- cc (collections)
Need number of collections in mongo_db. In the above case result 3
How can i get???
in mongo shell you could use db.getCollectionNames().length
I will use db.stats()
which as specified in the documentation:
Returns statistics that reflect the use state of a single database.
Demo:
> show collections
coll
collection
foo
mumbai
spam
> db.stats()
{
"db" : "test",
"collections" : 5,
"views" : 0,
"objects" : 14,
"avgObjSize" : 154.64285714285714,
"dataSize" : 2165,
"storageSize" : 98304,
"numExtents" : 0,
"indexes" : 5,
"indexSize" : 98304,
"ok" : 1
}
> db.stats().collections
5
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