我在我的mongo中有这个对象。在"conditions.all“数组中,有一个对象列表,其中包含字段fact、operator和value。我需要一个查询来查找文档,在该文档中,对象中的年值具有事实:" year ",例如,在本例中,值1970,比较此值是大于还是小于输入值
{
"_id": { "$oid": "5fc14323bd1f87002e8ca7ac" },
"priority": { "$numberInt": "6" },
"type": "pricing",
"name": "BLOCK AUDI A6",
"conditions": {
"all": [
{ "fact": "brand", "operator": "equal", "value": "AUDI" },
{ "fact": "model", "operator": "equal", "value": "A6" },
{
"fact": "version",
"operator": "in",
"value": [
"3.0 TFSI QUATTRO V6 24V GASOLINA 4P TIPTRONIC",
"2.0 TFSI AMBIENTE GASOLINA 4P S-TRONIC",
"3.0 TFSI ALLROAD 24V GASOLINA 4P S-TRONIC",
"3.0 TFSI QUATTRO V6 24V GASOLINA 4P S-TRONIC"
]
},
{
"fact": "km",
"operator": "greaterThanInclusive",
"value": { "$numberInt": "0" }
},
{
"fact": "km",
"operator": "lessThanInclusive",
"value": { "$numberInt": "1000000" }
},
{
"fact": "year",
"operator": "greaterThanInclusive",
"value": { "$numberInt": "1970" }
}
]
},...我目前正在使用一个查询来检查整个数组中的值,如下所示:
this.getCollection().aggregate({ $match: {"conditions.all.value":{$lte:2050} } })但是现在我需要检查由事实字段指定的对象内部的值
发布于 2020-12-03 19:25:15
我认为这个查询对这个问题很有帮助:
this.getCollection().aggregate({$match:{$and:[{"conditions.all.fact":"year"}, {"condition.all.value":{$or:[{$lte:1970},{$gte:1970}]}}]}})
https://stackoverflow.com/questions/65117378
复制相似问题