0

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"
         }        
    }      
}
4
  • $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.
    – Neil Lunn
    Commented Jul 10, 2014 at 10:46
  • well just bceause auth criteria is what mentioned in the documentation this does not mean that we can implement in other use cases... here I am trying almost the same idea, but just want to stop once a specific level is reached. if you type { $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
    – anvarik
    Commented Jul 10, 2014 at 11:45
  • $$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.
    – Neil Lunn
    Commented Jul 10, 2014 at 11:53
  • It is the fastest possibility that I currently have. Using your unwind and map does not do the job as fast as redact. About current and root, if you know how they are defined, maybe you can help me explaining why second did not match and first matched
    – anvarik
    Commented Jul 10, 2014 at 14:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.