I'm trying to do a keyword search in my mongoDB database. In the mongoDB console:
db.logs.find({$text: {$search: 'key1'}})
gives the correct result. But when I use mongoose-text-search on my nodejs controller I get an error. This is the definition of the schema:
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var textSearch = require('mongoose-text-search');
var Log = new Schema({
keywords: [String],
description: String,
videoId: String,
logId: String,
date: Date,
robot: String
});
Log.plugin(textSearch);
Log.index({ keywords: 'text' });
module.exports = mongoose.model('log', Log);
and in the controller, at certain point I do:
Log.textSearch('key1', function(err,output) {
if (err){
res.send(500,err);
} else {
console.log(output);
}
});
and the response is:
{"name":"MongoError","message":"no such command: text","ok":0,"errmsg":"no such command: text","code":59,"bad cmd":{"text":"logs","search":"key1"}}
now, that message alone would make you think that text search is not working, but it is as I showed before. I'm running MongoDB shell version 3.0.2 so text search is enabled by default.