特定搜索的MongoDB统计信息 [英] MongoDB Stats for a particular search

查看:73
本文介绍了特定搜索的MongoDB统计信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在MongoDB外壳中找到一个函数,该函数可以让我查看特定查询中有多少个项目.

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.

MongoJSMongoDb的其他前端实现中,查询返回一个对象,您可以在该对象上执行.length方法,例如:

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

有什么办法可以在Shell本身中做类似的事情?会非常有用,但我找不到任何文档或任何提及此的地方.

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().

或者如Stennie所指出的,您也可以使用db.collection.count({category: "Cupcakes"})

Or as pointed by Stennie you can also use db.collection.count({category: "Cupcakes"})

这篇关于特定搜索的MongoDB统计信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆