$6.55

How to list all Collections with their records' amount in Mongodb

Ask a question+
1

Can you please help me to list all collections with their records’ amount

add comment

1 Answer

1

I find the solution

var collections = db.getCollectionNames();
for(var i = 0; i < collections.length; i++){
  var name = collections[i];
  if(name.substr(0, 6) != 'system'){
      var c = db.getCollection(name).count() ;
      print(name + ' - ' + c + ' records');
  }
}
add comment

Your Answer