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

Resolve ambiguity of positional projections with multiple implicit array traversal predicates in certain cases

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major - P3
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: Backlog
    • Component/s: Querying
    • Labels:
      None

      Description

      In general, if there are multiple query predicates that require implicit array traversal, the behavior of the positional projection operator is undefined. For instance, should the following projection return the zeroth or first array element?

      db.collection.drop();
      db.collection.insert({a:[{b:1},{c:1}]});
      db.collection.find({"a.b":1,"a.c":1},{"a.$":1}); // Return "a.0" element, or "a.1" element?
      

      SERVER-14662 tracks work to make such queries return an error to the user.

      However, there are cases in which this ambiguity can be resolved. Consider the following projection:

      db.collection.drop();
      db.collection.insert({a:[{b:1},{c:1}],d:[{e:1},{f:1}]});
      db.collection.find({"a.b":1,"d.f":1}, {"a.$":1});
      

      In this case, we can resolve the ambiguity because "a.$" matches the prefix of path "a.b" but does not match a prefix of path "d.f".

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              backlog-query-optimization Backlog - Query Optimization
              Reporter:
              rassi J Rassi
              Participants:
              Votes:
              3 Vote for this issue
              Watchers:
              17 Start watching this issue

                Dates

                Created:
                Updated: