MongoDB Stats for a particular search

谁都会走 提交于 2019-12-13 05:24:28

问题


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.


回答1:


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"})



来源:https://stackoverflow.com/questions/20230499/mongodb-stats-for-a-particular-search

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!