I'd like to find a function within the MongoDB
shell that will let me see how many items are in a particular query.
For instance, I want to do something akin to:
db.collection.find({category: "Cupcakes"}).stats()
and see count, file size, that sort of thing.
In MongoJS
and other front-end implementations of MongoDb
a query returns an object that you can perform a .length
method on, like:
db.collection.find({category: "Cupcakes"}, function(err, records){
console.log(records.length); // Shows how many records are in the search field
});
Any way to do something similar in the shell itself? Would be insanely useful but I can't find any docs or mention anywhere of this.
This function is count(). All you need is to do:
db.collection.find({category: "Cupcakes"}).count()
.Or as pointed by Stennie you can also use
db.collection.count({category: "Cupcakes"})