Equivalent to mongo shell db.collection.runCommand() in Node.js
Asked Answered
U

2

1

I'd like to use full text search available in MongoDB 2.4. Text search is available through runCommand function e.g. db.collection.runCommand( "text", { search: "keywords"}). So, I'm wondering whether there is an equivalent to runCommand() function in mongojs or node-mongodb-native modules.

I know the question has been touched before but was never answered sufficiently. Thanks in advance.

Uraeus answered 8/6, 2013 at 18:46 Comment(4)
btw, I've tried db.executeDbCommand({text:'comics', search:"you"},function(err, result) {});. result.documents['results'] variable is always an empty array, though.Uraeus
The invocation looks correct to me. Are you sure you're not just getting an error ? For example, when I try the command without enabling text search I get something like { documents: [ { ok: 0, errmsg: 'text search not enabled' } ] ...} but note that err from the callback was still null. Even if you have text search enabled you still might be getting another error.Ironbark
Thanks for your comment jimoleary. AFAICS there are no errors, here is the response: { documents: [ { queryDebugString: '||||||', language: 'english', results: [], stats: [Object], ok: 1 } ], index: 200, messageLength: 200, requestId: 2, responseTo: 3, responseFlag: 8, cursorId: { bsontype: 'Long', low: 0, high_: 0 }, startingFrom: 0, numberReturned: 1 }Uraeus
btw, 'comics' in aforementioned example is supposed to be the collection. Also, when I run the command from mongo shell I do get results, and queryDebugString key equals "<keywords>||||||" rather than "||||||" which means that my keywords are not even passed.Uraeus
U
0

runCommand support has been added! https://github.com/gett/mongojs/issues/62

Uraeus answered 24/6, 2013 at 12:22 Comment(1)
Were you able to get mongojs working for this? I've tried with no luck.Effects
S
1

I found that as an equivalent:

collection.find({ $text: { $search : "your search words" }})
  .toArray(function(err,results) {
    // ..callback stuff..
});
Strutting answered 23/6, 2014 at 16:23 Comment(0)
U
0

runCommand support has been added! https://github.com/gett/mongojs/issues/62

Uraeus answered 24/6, 2013 at 12:22 Comment(1)
Were you able to get mongojs working for this? I've tried with no luck.Effects

© 2022 - 2024 — McMap. All rights reserved.