我正在將我的 SQL 查詢轉換為 MongoDB。我有以下 SQL 陳述句,它檢查輸入并相應地執行查詢。
(score_min = -1 OR Scores BETWEEN score_min AND score_max)
Scores 是一個欄位名稱,我想過濾它
仍然無法找出在 MongoDB 聚合管道中執行此查詢的最佳方法。請問有什么建議嗎?
uj5u.com熱心網友回復:
您可以$expr使用簡單的find. 不是必須使用聚合管道。
db.collection.find({
$expr: {
$or: [
{
// $eq: [<score_min>, -1]
$eq: [
<score_min>,
-1
]
},
{
$and: [
{
// $gte: ["$Scores", <score_min>]
$gte: [
"$Scores",
<score_min>
]
},
{
$lte: [
// $gte: ["$Scores", <score_max>]
"$Scores",
<score_max>
]
}
]
}
]
}
})
這是Mongo 游樂場供您參考。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/374681.html
下一篇:如何保護MongoDB?我被黑了
