NodeJS 如何在时间序列集合中搜索文本?

6ljaweal  于 5个月前  发布在  Node.js
关注(0)|答案(2)|浏览(61)

我尝试使用条件{ $text: { $search: searchContent } }搜索文本。这需要文本索引。但是,text index is not supported by time series。我该怎么办?

2j4z5cfb

2j4z5cfb1#

尝试使用{"field": {"$regex": "value-to-search"}}作为您的查询,这是最接近文本搜索而不使用文本搜索,正如您提到的,它不支持,根据您提供的链接,它可能不会。

wwtsj6pe

wwtsj6pe2#

如果你知道你找到的字段,你可以使用$regex same @omercotkd suggest。在这里,我使用$where来搜索所有字段。

db.collection.find({
    $expr: {
        $function: {
            body: function(all_field) {
                for (var field in all_field) {
                    if (all_field[field] == searchContent) return true;
                }
                return false;
            },
            args: [ "$$ROOT" ],
            lang: "js"
        }
    }
})

字符串

相关问题