0

我需要帮助试图找出创建查询以搜索关键字数组的最佳方式。

我希望能够与["work", "hi"]模式中的数组相比,使用数组进行搜索

["work", "school"]并且应该返回这个文件。现在我正在使用

this.resumes.find({
    keywords: {
        $all: term.split(' ')
    }
}).limit(50)
.select('-keywords').exec(function (err, resumes) {});

但这只有在搜索数组中都在模式数组中时才有效。那么如何进行部分匹配呢?

4

2 回答 2

0
this.resumes.find({$or: [{keywords: term1}, {keywords: term2}]})
于 2013-08-18T05:56:51.100 回答
0

我认为使用$in运算符会使这更容易:

this.resumes.find({ keywords: { $in: [ "work", "hi" ] } })

基本上,$or在单个数组字段上。从文档:

$in 选择字段值等于指定数组中任何值的文档

于 2013-08-18T06:48:50.700 回答