Mongoose,nodejs,全文search

我正在尝试使用Mongoose和nodejs设置一个简单的关键字全文search,这是迄今为止的代码:

var db = mongoose.createConnection('localhost', config.mongoDbName) , ContSchema = Schema({ 'idUser': String, 'title': String, 'category': String, 'slug': String, 'description': String }) .index({ 'title':'text', 'description':'text' }) , ContModel = db.model('Cont', ContSchema); db.on('error', function (err) { console.error.bind(console, 'Mongoose connection error:' + err); }); db.once('open', function () { process.stdout.write('Connection to mongodb db done...'); }); 

然后我做search查询:

 var getAllBy = function (limit, offset, keywords) { var sort , find , findScore; if (!!keywords) { find = {'$text':{'$search':keywords}}; findScore = {'score':{'$meta':'textMatchScore'}}; sort = {'score':{'$meta':'textMatchScore'}}; } else { sort = {'_id':'desc'}; } return new RSVP.Promise(function (resolve, reject) { ContModel.find(find, findScore).limit(limit).skip(offset).sort(sort).exec(function (err, data) { if (err){ reject(err); } else { resolve(data); } }); }); } 

它不工作,它在控制台中返回这个错误: MongoError:无法canonicalize查询:BadValue错误的sorting规范

我实际上无法find真正的问题,你能帮我吗?

谢谢

Solutions Collecting From Web of "Mongoose,nodejs,全文search"