[英]Find a Mongodb document if it contains an element in the array in mongoose
[英]Mongoose / MongoDB find if element in input array is in a schema attribute keyword array
我需要幫助來弄清楚如何創建查詢關鍵詞數組的最佳方法。
我希望能夠使用數組["work", "hi"]
與模式中的數組進行比較
["work", "school"]
並應退還此文件。 現在我正在使用
this.resumes.find({
keywords: {
$all: term.split(' ')
}
}).limit(50)
.select('-keywords').exec(function (err, resumes) {});
但這僅在搜索數組中的兩個都在架構數組中時才起作用。 那我怎么做部分比賽呢?
this.resumes.find({$or: [{keywords: term1}, {keywords: term2}]})
我認為使用$in
運算符將使此操作更容易:
this.resumes.find({ keywords: { $in: [ "work", "hi" ] } })
基本上,單個數組字段上的$or
。 從文檔:
$ in選擇文檔,其中字段值等於指定數組中的任何值
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.