1
什麼是像這樣在MongoDB中編寫條件的最佳模式:
field > 5 or (field = 5 and field2 > 3)
是這樣嗎?
$or: [ { field: { $gt: 5 } }, { $and: [ { field: { $eq: 5 } }, { field2: { $gt: 3 } } ] } ]
或者還有另一種更好的模式?
什麼是像這樣在MongoDB中編寫條件的最佳模式:
field > 5 or (field = 5 and field2 > 3)
是這樣嗎?
$or: [ { field: { $gt: 5 } }, { $and: [ { field: { $eq: 5 } }, { field2: { $gt: 3 } } ] } ]
或者還有另一種更好的模式?
那麼有沒有理由不會是,但因爲所有 MongoDB的查詢參數已經是「AND」條件,除非另有明確,否則,它也可能只是:
{
"$or": [
{ "field": 5 },
{
"field": { "$gt": 5 }
"field2": { "$gt": 3 }
}
]
}