During a $redact
pipe, is it possible to know under which array the current document is residing? For example imagine running a $redact
pipe on the following document structure:
arrayOut : [
...
arrayIn1: [
...
],
arrayIn2: [
...
]
]
I would like to know whether the document is being processed under arrayIn1
or not. I tried the following, but no luck:
redact :{
$cond :{
"if": {
$or : [
{ $eq : ["$$CURRENT" , "$$ROOT"] }, // match the most outer structure
{ $setIsSubset : [["$$CURRENT"] , "$$ROOT.arrayIn1"] } // never true
]
},
"then" : "$$DESCEND",
"else" : "$$PRUNE"
}
}
}
$redact
works recursively, especially with$$DESCEND
, and there is no exposure of which "level" it is currently at or which "element" it is processing in. The primary intent is "redaction" of document levels that do not meet the specified "auth" criteria. Goverment and legal want this for example. You seem to be trying to "shoehorn" this pipeline stage into a purpose it is not designed for.{ $eq : ["$$CURRENT" , "$$ROOT"] }
you can see on your own that it stops after the outmost level, i believe that there should be a way for other levels as well$$CURRENT
and$$ROOT
are defined as being quite different. I have already warned you about this before, as$redact
is not really suited to what you seem to be trying to apply it to. It also does a fair bit of un-necessary processing due to the recursive nature, as I already know from previous posts you are looking at this as an array filter. I have already told you to use$map
instead if you want to avoid$unwind
.