Reputation: 119
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
Upvotes: 1
Views: 1496
Reputation: 119
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);
}
});
Upvotes: 3