Details
-
Improvement
-
Status: Open
-
Minor - P4
-
Resolution: Unresolved
-
None
Description
It would be nice, if it's possible to access the parent within a $redact Aggregation.
Example:
{
|
id: ...,
|
i18n: {
|
en: {
|
foo: "bar",
|
_lang: "en"
|
},
|
jp: {
|
foo: "baz",
|
_lang: "jp"
|
}
|
}
|
}
|
Now I'd like to retrieve everything with i18n = jp, and keep a fallback to i18n = en. The code could look like this:
{ $redact: {
|
$cond: {
|
if: {
|
$or: [
|
{ $not : "$_lang" },
|
{ $eq: [ "$_lang", "jp" ] },
|
{ $and: [
|
{ $eq: [ "$_lang", "en" ] },
|
{ $not: "$$PARENT.jp" }
|
]}
|
]
|
},
|
then: "$$DESCEND",
|
else: "$$PRUNE"
|
}
|
}}
|
Thank you!