如何在 MongoDB 的文本搜索中查看 "queryDebugString"?

How to see the "queryDebugString" on MongoDB's Text Search?

我正在尝试 MongoDB 中的文本搜索功能,并且在互联网上我可以看到很多信息,人们会这样做:

db.posts.runCommand("text", {search: '"robots are crazy"'})

得到这个:

{
    "queryDebugString" : "robot||||robots are||",
    "language" : "english",
    "results" : [
        {
            "score" : 0.6666666666666666,
            "obj" : {
                "_id" : ObjectId("50ebc482214a1e88aaa4ad9e"),
                "txt" : "Robots are superior to humans"
            }
        }
    ],
    "stats" : {
        "nscanned" : 2,
        "nscannedObjects" : 0,
        "n" : 1,
        "timeMicros" : 185
    },
    "ok" : 1
}

我知道 runCommand("text", ... 已被弃用,但我也尝试了 db.posts.find({ $text: { $search: '"robots are crazy"' } }) 方法,但什么也没有。

如何查看此 "queryDebugString" 属性?我一直在寻找启动 mongod 时要使用的某种调试标志,但找不到任何东西。

试试这个:

db.posts.find({ "text" : '"robots are crazy"' })

现在 Mongo,操作变成(在基本状态下)类似于:

db.collection.action({query}}

我认为这足以开始,但请尝试转到 MongoDB 文档:

http://docs.mongodb.org/manual/

对于 Mongo 的更新版本(至少 2.6),使用 .explain(true) 作为详细输出,它将包含一个 parsedTextQuery 字段,其中包含更多、更易读的信息比 queryDebugString:

> db.test.find({ "$text" : { "$search" : "cows are lovely" } }).explain(true)
{
    "cursor" : "TextCursor",
    ...
    "stats" : {
        "type" : "TEXT",
        ...
        "parsedTextQuery" : {
            "terms" : ["cow", "love"],
            "negatedTerms" : [],
            "phrases" : [],
            "negatedPhrases" : []
        ]
    }
    ...
}