相当于nodejs-native-mongodb的runCommand [英] runCommand equivalent for nodejs-native-mongodb

查看:71
本文介绍了相当于nodejs-native-mongodb的runCommand的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从nodejs内部利用MongoDB 2.4实验性文本搜索功能.唯一的问题是,据我所知,本机nodejs mongo驱动程序似乎不支持集合级runCommand.

I'm trying to utilize MongoDB 2.4 experimental text search feature from within nodejs. The only problem is, native nodejs mongo drivers don't seem to support collection-level runCommand, as far as I can tell.

Mongo shell语法如下:

The Mongo shell syntax looks like this:

db.collection.runCommand( "text", { search : "Textvalue" } );

它出现了一个db.command/db.executeDbCommand函数,但是我不知道如何选择一个集合并使用它运行文本命令(如果可能的话),因为它需要在集合上级别,而不是数据库级别.

There is a db.command / db.executeDbCommand function it appears, but I don't know how to choose a collection and run the text command using it (if it is possible), as it needs to be on the collection level and not the db level.

任何帮助将不胜感激

推荐答案

我通过利用Asya Kamsky的评论结合使用

I managed to get it working through a combination of Asya Kamsky's comment, by utilizing

this.db.command({text:"collection" , search: "phrase" }).

问题在于它没有像标准结果那样返回,因此toArray()调用失败.相反,我将回调直接放在里面:

The problem was it isn't returned like a standard result so a toArray() call was failing. Instead, I put the callback directly inside:

this.db.command({text:"collection" , search: "phrase" }, function(err, cb){ 

这篇关于相当于nodejs-native-mongodb的runCommand的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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