Hello,
I´m using db version 4.2.12.
I’m trying to use the $size and $setIntersection just like in the $redact example on mongo documentation:
$redact: {
$cond: {
if: { $gt: [ { $size: { $setIntersection: [ "$tags", userAccess ] } }, 0 ] },
then: "$$DESCEND",
else: "$$PRUNE"
}
}
but it gives an error "The argument to $size must be an array but was of type null.
I have a Security Object at root level with a string array field inside (just like the example). The Security object is also inside an Embedded array of objects of which I would like to return only the objects that intersect with the Security Object string array. Can you help me please?
My Code:
$redact: {
$cond: {
'if': {
$gt: [
{
$size: {
$setIntersection: [
'$Programmes.Security.AccessTeams',
[
'Lorem1'
]
]
}
},
0
]
},
then: '$$DESCEND',
'else': '$$PRUNE'
}
}
Document Example:
{
"_id": {
"$oid": ""
},
"PXXXXXID": "Lorem",
"PXXXXXDescription": "Lorem",
"PXXXXXXXs": [
{
"PXXXXXXID": "Lorem",
"Security": {
"DXXXXXXX": "Lorem",
"AccessTeams": [
"Lorem1"
]
}
},
{
"PXXXXXXID": "Lorem",
"Security": {
"DXXXXXXX": "Lorem",
"AccessTeams": [
"Lorem2"
]
}
}
],
"UXXXXXXXPXXXX": {
"UXXXID": "Lorem",
"Security": {
"DXXXXXXX": "Lorem",
"AccessTeams": [
"Lorem1"
]
}
},
"Security": {
"DXXXXXXX": "Lorem",
"OwningTeam": "Lorem",
"AccessTeams": [
"Lorem1"
]
}
}
Thank you