examples/mongo/collectionNames-and-count.js

19 lines
350 B
JavaScript
Raw Normal View History

2021-07-12 14:05:44 +02:00
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
// }
// ]