1

In mongo shell I can do this

db.collection.runCommand( 'text', { search: 'query' } )

And how can I get this with mongodb-native and node.js?

I tried to do something like this

db.executeDbCommand( 'text', { search:'query' }, function(e, o) {
    if (e) {
        callback(e)
    }
    else callback(o)
});

and it's failed

user2194521
  • 119
  • 8
  • 1
    I think you can follow this link [here][1] [1]: http://stackoverflow.com/questions/16070233/runcommand-equivalent-for-nodejs-native-mongodb – CKD Apr 21 '13 at 02:30

1 Answers1

3

Solution is pretty simple

exports.search = function(query, callback) {
db.command({ text: 'collectionName', search: query }, function(e, o) {
    if (e) {
        console.log(e, 'error')
    }
    else callback(o)
});
}

And in callback

DB.search(query, function(o){
    if (o) {
        console.log(o.results);
    }
});
user2194521
  • 119
  • 8