I am using react native and mongoDB stitch. My intention is, when I run query with a keyword, the result should be sorted with most match with keyword,
As example, If I search for Aqua, the result should be sorted as
- Aqua
- Aquae
- Aquatica
- Aquatica extract
- Aqua-water
- etc.
I found a documentation for this (https://docs.mongodb.com/manual/reference/operator/projection/meta/)
db.collection.find(
<query>,
{ score: { $meta: "textScore" } }
).sort( { score: { $meta: "textScore" } } )
But can not find how to write this code for mongodb stitch,
I have tried as
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)
})
Its crashing saying 'unknown operator $meta'. Did not find any example in mongdb stitch documentation.
Any suggestion?