runCommand equivalent for nodejs-native-mongodb
Asked Answered
W

1

6

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.

The Mongo shell syntax looks like this:

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

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.

Any help would be appreciated

Wellworn answered 17/4, 2013 at 21:4 Comment(2)
you can use database level command: db.runCommand({text:"collectionName", search: etc})Roney
In node, this.db.command({text:"collection" , search: "phrase" }) isn't giving any return. Maybe the syntax is off. =/Wellworn
W
15

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

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

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){ 
Wellworn answered 17/4, 2013 at 22:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.