positional operator in projection fails when combined with other array fields

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Incomplete
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Querying
    • None
    • ALL
    • Hide

      1. Create a collection with documents containing to array fields with inner documents in each.
      2. Query for:

      db.collection.find({ "array1" : { $elemMatch : { "key1" : "value1", "key2" : "value2" } } }, { "array1.$" : 1, "array2.other_field" : 1 })
      
      Show
      1. Create a collection with documents containing to array fields with inner documents in each. 2. Query for: db.collection.find({ "array1" : { $elemMatch : { "key1" : "value1", "key2" : "value2" } } }, { "array1.$" : 1, "array2.other_field" : 1 })
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Combining a positional operator in the projection with some other array dotted field returns:
      "BadValue: positional operator element mismatch"

      Example:

      db.collection.find({ "my_array" : { $elemMatch : { "key1" : "value1", "key2" : "value2" } } }, { "my_array.$" : 1, "some_other_array.other_field" : 1 })

      returns the error message.

      db.collection.find({ "my_array" : { $elemMatch : { "key1" : "value1", "key2" : "value2" } } }, { "my_array.$" : 1 })

      returns the expected result.

      According to the docs at:
      https://docs.mongodb.com/manual/reference/operator/projection/positional/

      Only one array field, the one being limited with the $ projection operator, should appear in the query document. Additional array fields in the query document may lead to undefined behavior

      But there is no similar limit on the projection document.

              Assignee:
              Mark Agarunov (Inactive)
              Reporter:
              Mor [X]
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

                Created:
                Updated:
                Resolved: