获得对文本搜索 mongodb 的计数 [英] get a count on a text search mongodb

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

问题描述

我在 mongo 2.4 中对作业集合设置了全文搜索索引.我可以使用以下内容获取全文搜索结果:

I have a full text search index set up in mongo 2.4 on the jobs collection. I can get full text search results using something like this:

db.jobs.runCommand("text", { search: "Australia" })

有没有办法计算类似于 db.jobs.count() 的计数?限制怎么样?

Is there a way to get a count on this similar to db.jobs.count()? How about a limit?

推荐答案

您想在输出中使用某个字段:

You want to use a certain field in the output:

http://docs.mongodb.org/manual/reference/command/text/#text.stats.nfound

哪个会给你一个数字:

nfound 字段返回匹配的文档总数.这个数字可能大于结果数组的大小,即 n,如果结果集超过 BSON 文档大小.

The nfound field returns the total number number of documents that match. This number may be greater than the size of the results array, i.e. n, if the result set exceeds the BSON Document Size.

示例

print(db.jobs.runCommand("text", { search: "Australia" }).stats.nfound);

这篇关于获得对文本搜索 mongodb 的计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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