How To Get Row Count And Collection Size For All Collections At Once

3,059 views
Skip to first unread message

Bob Delamater

unread,
Dec 16, 2013, 12:03:30 PM12/16/13
to mongod...@googlegroups.com
Hello, 

Is there a way to get the row count for all collections in a MongoDB at once? Is it also possible to get the data size and index size for each collection at the same time?

Thanks,
Bob

Sridhar

unread,
Dec 16, 2013, 6:53:57 PM12/16/13
to mongod...@googlegroups.com
There is no single command to do this for all collections. if you want to do this in a single db in the shell you could do
for (index = 0; index < collNames.length; index++) {  
  var coll = db.getCollection(collNames[index]);
  var stats = coll.stats();
  print(stats.ns, stats.count, stats.size, stats.totalIndexSize); }

Asya Kamsky

unread,
Dec 17, 2013, 1:25:09 AM12/17/13
to mongodb-user
As long as you are in the shell, you can also use the shell helper 

> db.printCollectionStats()

Of course this is in a single database, not all of 'mongod'...

Asya



--
--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com
To unsubscribe from this group, send email to
mongodb-user...@googlegroups.com
See also the IRC channel -- freenode.net#mongodb
 
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages