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

positional operator in projection fails when combined with other array fields

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Incomplete
    • Icon: Major - P3 Major - P3
    • None
    • None
    • 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 })

    Description

      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.

      Attachments

        Activity

          People

            mark.agarunov Mark Agarunov
            Marmor Mor [X]
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: