Running the following text search directly on MongoDB results in no issues:
db.getCollection(\'schools\').find({
$text:
{
$search: \'some query s
OK, according to this bug since the version 3.0.0 find
and findOne
no longer support the fields
parameter and the query needs to be rewritten as follows:
collection.find({
$text:
{
$search: filter,
$caseSensitive: false,
$diacriticSensitive: true
}
})
.project({ score: { $meta: "textScore" } })
.sort({score:{$meta:"textScore"}})
In the current version of the native MongoDB driver, you need to include the projection key among the options for find:
const results = await collection.find(
{
$text: { $search: filter }
},
{
projection: { score: { $meta: 'textScore' } },
sort: { score: { $meta: 'textScore' } },
}
).toArray();