"" , , . $size $redact.
$setIsSubset, , , "" . , :
"$setIsSubset": [[1,0],[1]]
, , false. , , , ( 0), "" "" . "" , :
"$setIsSubset": [[1],[1]]
, , "" .
, "", :
db.world.aggregate([
{ "$match": { "country.3": { "$exists": true } }},
{ "$redact": {
"$cond": {
"if": {
"$gte": [
{ "$size": { "$setDifference": [
{ "$map": {
"input": "$country",
"as": "el",
"in": {
"$cond": {
"if": { "$eq": [ "$$el.type", 1 ] },
"then": "$$el",
"else": false
}
}
}},
[false]
]}},
4
]
},
"then": "$$KEEP",
"else": "$$PRUNE"
}
}}
])
, "set" $setDifference, false , . $size, , $$PRUNE, .
$map , , false , .
, , , , "", MongoDB $filter, , , "set":
db.world.aggregate([
{ "$match": { "country.3": { "$exists": true } }},
{ "$redact": {
"$cond": {
"if": {
"$gte": [
{ "$size": { "$filter": {
"input": "$country",
"as": "el",
"cond": {
"$eq": [ "$$el.type", 1 ]
}
}}},
4
]
},
"then": "$$KEEP",
"else": "$$PRUNE"
}
}}
])
, , , , $unwind $match , "" $group:
db.world.aggregate([
{ "$match": { "country.3": { "$exists": true } }},
{ "$project": { "country": 1, "countryCopy": "$country" } },
{ "$unwind": "$country" },
{ "$match": { "country.type": 1 } },
{ "$group": {
"_id": "$_id",
"country": { "$first": "$countryCopy" }
"count": { "$sum": 1 }
}},
{ "$match": { "count": { "$gte": 4 } }}
])
, , , .
$match, , ( n-1), , , , 4 .
$exists , . , - .