Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-17038

$$PARENT for $redact Aggregations

    • Query Execution

      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!

            Assignee:
            backlog-query-execution [DO NOT USE] Backlog - Query Execution
            Reporter:
            benneq Benjamin M
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: