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

warn when more than one array is used in a query with $ projection operator

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

      When you query for a value on each of two arrays, both with positional operators, the $ projection operator can get pretty confused but smoothly performs the wrong operation.

      Steps to reproduce:

      Perform the following operations in the shell:

      db.foo.insert( { a : [5, 6, 7, 8], b : [ 11, 12, 13, 14] } )
      db.foo.find( { a : 7, b : 11 }, { "a.$" : 1 , _id : 0 } 
      

      Expected result:

      { "a" : 7 }

      or an exception

      Actual result :

      { "a" : 5 }

      Related documentation:

      The following doc tells me not to do exactly what I did: http://docs.mongodb.org/manual/reference/operator/projection/positional/#proj._S_

      "Only one array field can appear in the query document; i.e. the following query is incorrect:" (then the example shows me exactly what I did), but this is clearly a case where either an exception should be thrown, or else the $ operator should be made smarter.

            Assignee:
            hari.khalsa@10gen.com hari.khalsa@10gen.com
            Reporter:
            william.cross William Cross
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: