[英]why this mongoose text search doesn't work
Even though I have similar data in collection, result always comes back empty. 即使我收集了相似的数据,结果也总是空着。 I have ingredients in array[object].
我在array [object]中有成分。 That means qty:1 unit:spoon ing:salt and I want only
ing
to be searchable. 这意味着数量:1单位:勺子ing:盐,我只希望
ing
是可搜索的。 I have mongoose debug enabled and it shows: 我启用了猫鼬调试功能,它显示:
Mongoose: recipes.ensureIndex({ 'Ingridients.ing': 'text' }) { background: true, safe: undefined }
This is the code: 这是代码:
var RecipesSchema = new mongoose.Schema({
Name: {type: String, required: true},
Desc: String,
Ingridients: [{qty:Number, unit:String, ing:{ type: String, index: "text" } }],
created: { type: Date }
});
Recipe.find({ $text : { $search : "salt egg potato peper" } },
{ score : { $meta: "textScore" }
})
.sort({ score : { $meta : 'textScore' } })
.exec(function(err, recipe) {
// callback
if(err) console.log(err);
res.render('list', { recipes: recipe });
});
after i tried on localhost and it worked, switched on mongolab.com by dropping and recreating collection and indexes again. 在尝试在localhost上运行之后,通过删除并重新创建集合和索引来打开mongolab.com。 it was not able to index correctly
它无法正确索引
ERR: planner returned error: need exactly one text index for $text query', code: 17007
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.