未知操作员:$search管道MongoDB Stitch



我正在尝试通过新的MongoDB功能缝合使用文本运算符运行查询。我已经尝试了一些选项,但呼叫响应如下消息:

未知操作员:$search

如何解决此错误?

我还创建了文本索引。

{
"v" : 2,
"key" : {
"_fts" : "text",
"_ftsx" : 1
},
"name" : "script_text_description_text",
"ns" : "test.scripts",
"weights" : {
"description" : 1,
"script" : 1
},
"default_language" : "english",
"language_override" : "language",
"textIndexVersion" : 3
}

尝试 #1:

client.executePipeline([{
"service": "mongodb-atlas",
"action": "aggregate",
"args": {
"database": "test",
"collection": "scripts",
"pipeline": [{
$match: {
$text: {
$search: "docker"
}
}
}
]
}
}])

尝试#2:

db.collection('scripts').find({"$text":{"$search":'docker'}})

尝试 #3:

db.collection('scripts').aggregate([{
"$match": {
"$text": {
"$search": "docker"
}
}
}])

更新:

我应用了这项工作。

import { StitchClientFactory,BSON } from 'mongodb-stitch';
let bsonRegex = new BSON.BSONRegExp(search, 'i')
// showLoading();
db.collection('clients').find({owner_id: client.authedId(),name:bsonRegex}).execute().then(docs => {
funct(docs);
// hideLoading();
});

Stitch 产品的 Beta 版本目前不支持 Stitch 管道聚合操作中的全文搜索,但我们希望在 Stitch 正式发布时支持它们。

2 年后,情况仍然相同,$textStitch 不支持:

https://mongodb.canny.io/mongodb-stitch/p/full-text-search

您是如何实现文本搜索的?现在MongoDB Atlas具有文本搜索功能,但它仅适用于M30和更大的集群:

https://docs.atlas.mongodb.com/full-text-search/?jmp=docs

最新更新