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

positional operator in projection fails when combined with other array fields

    • Type: Icon: Bug Bug
    • Resolution: Incomplete
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Querying
    • Labels:
      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 })

      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 Mark Agarunov
            Reporter:
            Marmor Mor [X]
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: