examples/mongo/collectionNames-and-count.js

19 lines
350 B
JavaScript

var result = [];
db.getCollectionInfos().forEach(function(collection) {
var collectionResult = {name: collection.name, count: db[collection.name].count()}
result.push(collectionResult);
});
printjson(result);
// resulting in:
// [
// {
// "name" : "test",
// "count" : 1
// },
// {
// "name" : "test2",
// "count" : 3
// }
// ]