【发布时间】:2020-01-21 06:56:54
【问题描述】:
我正在使用 react native 和 mongoDB 缝合。 我的意图是,当我使用关键字运行查询时,结果应该以与关键字最匹配的方式排序,
例如,如果我搜索 Aqua, 结果应排序为
- 水色
- 水族
- 水生植物
- 水生植物提取物
- 水之水
- 等
我找到了这方面的文档 (https://docs.mongodb.com/manual/reference/operator/projection/meta/)
db.collection.find(
<query>,
{ score: { $meta: "textScore" } }
).sort( { score: { $meta: "textScore" } } )
但是找不到mongodb缝合这个代码怎么写,
我试过了
const query = {
name: {
$regex: searchKeyword,
$options: 'i',
//"$meta": "textScore"
},
score: { "$meta": "textScore" } // not sure where to put it , Saying unknown operator $meta
};
const options = {
"sort": { "score": { $meta: "textScore" }}
};
db.collection(itemNameDB).find( query, options).toArray()
.then(results => {
console.log(results)
})
它的崩溃说'未知运算符 $meta'。在 mongdb 缝合文档中没有找到任何示例。
有什么建议吗?
【问题讨论】:
标签: mongodb sorting find meta mongodb-stitch