[英]Not able to create index using mongoose
我正在使用Mongoose的Node.js應用程序中構建搜索功能,並在Mongo中創建全文搜索索引:
postSchema = mongoose.Schema({
xx : String
.......
}).index({
'xx':'text'
});
Post = mongoose.model('Post',postSchema);
並執行如下搜索:
find = {'$text':{'$search':query}};
findScore = {'score':{'$meta':'textScore'}};
sort = {'score': {'$meta':'textScore'} };
Post.find(find, findScore).sort(sort).exec(function (err, data) {
if (err){
logging.log(err);
} else {
logging.log(data);
}
});
運行程序時,出現以下錯誤:“無法執行查詢:錯誤處理查詢\\ n計划者返回錯誤:$ text查詢僅需要一個文本索引”
任何幫助,將不勝感激。
一個集合最多可以有一個文本索引。 您需要檢查它先前創建的任何文本索引。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.