MongoDB和MongoJS-无法让runCommand用于文本查询

mic*_*ael 3 mongodb node.js mongojs

我的目标是使用Node的MongoDB(2.4.4)文本命令。从命令行可以正常工作。基于此先前的SO问题:相当于Node.js中的mongo shell db.collection.runCommand(),我尝试使用MongoJS(0.7.17),但未能成功。这是代码:

mongojs = require('mongojs');
var products = mongojs('localhost:27017/mydb').collection('products');
products.runCommand('text', {search: 'a'}, function (err, docs) {
   ...
});
Run Code Online (Sandbox Code Playgroud)

docs返回undefined,并且err为null。我可以执行常规功能,例如products.find()fine ...,并且可以在MongoDB命令行上执行搜索。有人知道如何做到这一点吗?

顺便说一句,这是文档包含在回调中的内容:

{
    "queryDebugString": "||||||",
    "language": "english",
    "results": [],
    "stats": {
        "nscanned": 0,
        "nscannedObjects": 0,
        "n": 0,
        "nfound": 0,
        "timeMicros": 55
    },
    "ok": 1
}
Run Code Online (Sandbox Code Playgroud)

顺便说一句,如果还有另一种方法可以让普通的本机驱动程序正常工作,那我很好。

小智 6

使用本机驱动程序,我可以从db对象运行以下命令:

var MongoClient = require("mongodb").MongoClient;
MongoClient.connect(database, function (err, db) {
    if (!err) {
        db.command({ distinct: "Messages", key: "session" }, function (err, result) {
            //more code here
        });
    }
});
Run Code Online (Sandbox Code Playgroud)

我注意到您正在从收集对象中运行命令,这可能是问题所在。