MongoDB和MongoJS-无法让runCommand用于文本查询 [英] MongoDB and MongoJS - can't get runCommand to work for text queries

查看:225
本文介绍了MongoDB和MongoJS-无法让runCommand用于文本查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

My goal is to use MongoDB's (2.4.4) text command from Node. It works fine from the command line. Based on this previous SO issue: Equivalent to mongo shell db.collection.runCommand() in Node.js, I tried using MongoJS (0.7.17) but can't make it go. Here is the code:

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

docs返回undefined,并且err为null.我可以执行常规功能,例如products.find()fine ...,也可以在MongoDB命令行上执行搜索.有谁知道该怎么做?

docs returns undefined and err is null. I can execute a normal function such as products.find() fine... and I can execute the search on the MongoDB command line. Anyone know how to make this go?

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

BTW, here is what docs contains in the callback:

{
    "queryDebugString": "||||||",
    "language": "english",
    "results": [],
    "stats": {
        "nscanned": 0,
        "nscannedObjects": 0,
        "n": 0,
        "nfound": 0,
        "timeMicros": 55
    },
    "ok": 1
}

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

BTW, if there's another approach to make this work with just the normal native driver, I'm fine with that.

推荐答案

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

Using the native driver I can run a command off of the db object as follows:

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

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

I noticed you are running the command off of the collection object, that might be the problem.

这篇关于MongoDB和MongoJS-无法让runCommand用于文本查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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