產品檔案:
title: 'product title',
price: 240,
tags: [ 'snacks', 'vegetable' ],
用戶搜索查詢:/search?tags=snacks,fruit,juice。在這里,用戶選擇了多個標簽 ( snacks, fruit and juice)。我想選擇至少包含用戶使用 mongodb 聚合管道搜索的標簽之一的所有檔案。
uj5u.com熱心網友回復:
您可以使用$in運算子查找欄位包含給定陣列中任何專案的檔案。
{
tags: {
$in: ['snacks', 'fruit', 'juice' ]
}
}
uj5u.com熱心網友回復:
$in
db.collection.find({
"tags": {
"$in": [
"snacks",
"fruit",
"juice"
]
}
})
mongoplayground
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/339451.html
標籤:MongoDB mongodb-查询 聚合
