If you are on Mongo 3.6 or greater, you could try using the $expr
operator. Which would then allow you to use $cond
.
$expr
Allows the use of aggregation expressions within the query language.
Their example can be found here
db.supplies.find( {
$expr: {
$lt:[ {
$cond: {
if: { $gte: ["$qty", 100] },
then: { $divide: ["$price", 2] },
else: { $divide: ["$price", 4] }
}
},
5 ] }
} )
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…