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

Allow projection of specific array elements by position

    • Type: Icon: Improvement Improvement
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Querying
    • Fully Compatible

      This appeared in SERVER-15013:

      It is ambiguous whether "0" refers to a nested field name or to a position in the array. For instance, what should the following projection return?

      t.insert({a: [{"0": "foo", "bar": "baz"}, {"a": "b"}]});
      t.find({}, {"a.0": 1});
      

      One answer is that "0" should be interpreted as an array position, meaning that we should project just the first array element. The transformed document would then be:

      {a: [ {"0": "foo", "bar": "baz"} ]}
      

      Another answer is that "0" should be interpreted just like any other field name, and should be used to project within each nested document. Under this interpretation, the result is:

      { "a" : [ { "0" : "foo" }, {  } ] }
      

      Our projection language chooses the latter interpretation.

            Assignee:
            Unassigned Unassigned
            Reporter:
            ramon.fernandez@mongodb.com Ramon Fernandez Marina
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: