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

$ projection does not support queries on multiple array fields

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.2.10
    • Component/s: Querying
    • Labels:
      None
    • ALL
    • Hide
      > db.u.find()
      > db.u.insert({spaces:['foo'], i18n:[{l:'en',x:1}, {l:'de', x:3}]})
      WriteResult({ "nInserted" : 1 })
      > db.u.insert({spaces:['bar'], i18n:[{l:'en',x:2}, {l:'de', x:4}]})
      WriteResult({ "nInserted" : 1 })
      > db.u.find({spaces:'bar', 'i18n.l':'en'}, {'i18n.$':1, spaces:1})
      { "_id" : ObjectId("58ad69e98d62dac604e9b186"), "spaces" : [ "bar" ], "i18n" : [ { "l" : "en", "x" : 2 } ] }
      > db.u.find({spaces:'bar', 'i18n.l':'de'}, {'i18n.$':1, spaces:1})
      { "_id" : ObjectId("58ad69e98d62dac604e9b186"), "spaces" : [ "bar" ], "i18n" : [ { "l" : "en", "x" : 2 } ] }
      // just above, it doesn't give the right language
       
      > db.u.drop()
      true
      > db.u.find()
      > db.u.insert({spaces:'foo', i18n:[{l:'en',x:1}, {l:'de', x:3}]})
      WriteResult({ "nInserted" : 1 })
      > db.u.insert({spaces:'bar', i18n:[{l:'en',x:2}, {l:'de', x:4}]})
      WriteResult({ "nInserted" : 1 })
      > db.u.find({spaces:'bar', 'i18n.l':'de'}, {'i18n.$':1, spaces:1})
      { "_id" : ObjectId("58ad6afbd58e080a9eb86638"), "spaces" : "bar", "i18n" : [ { "l" : "de", "x" : 4 } ] }
      > db.u.find({spaces:'bar', 'i18n.l':'en'}, {'i18n.$':1, spaces:1})
      { "_id" : ObjectId("58ad6afbd58e080a9eb86638"), "spaces" : "bar", "i18n" : [ { "l" : "en", "x" : 2 } ] }
      
      Show
      > db.u.find() > db.u.insert({spaces:[ 'foo' ], i18n:[{l: 'en' ,x:1}, {l: 'de' , x:3}]}) WriteResult({ "nInserted" : 1 }) > db.u.insert({spaces:[ 'bar' ], i18n:[{l: 'en' ,x:2}, {l: 'de' , x:4}]}) WriteResult({ "nInserted" : 1 }) > db.u.find({spaces: 'bar' , 'i18n.l' : 'en' }, { 'i18n.$' :1, spaces:1}) { "_id" : ObjectId( "58ad69e98d62dac604e9b186" ), "spaces" : [ "bar" ], "i18n" : [ { "l" : "en" , "x" : 2 } ] } > db.u.find({spaces: 'bar' , 'i18n.l' : 'de' }, { 'i18n.$' :1, spaces:1}) { "_id" : ObjectId( "58ad69e98d62dac604e9b186" ), "spaces" : [ "bar" ], "i18n" : [ { "l" : "en" , "x" : 2 } ] } // just above, it doesn't give the right language > db.u.drop() true > db.u.find() > db.u.insert({spaces: 'foo' , i18n:[{l: 'en' ,x:1}, {l: 'de' , x:3}]}) WriteResult({ "nInserted" : 1 }) > db.u.insert({spaces: 'bar' , i18n:[{l: 'en' ,x:2}, {l: 'de' , x:4}]}) WriteResult({ "nInserted" : 1 }) > db.u.find({spaces: 'bar' , 'i18n.l' : 'de' }, { 'i18n.$' :1, spaces:1}) { "_id" : ObjectId( "58ad6afbd58e080a9eb86638" ), "spaces" : "bar" , "i18n" : [ { "l" : "de" , "x" : 4 } ] } > db.u.find({spaces: 'bar' , 'i18n.l' : 'en' }, { 'i18n.$' :1, spaces:1}) { "_id" : ObjectId( "58ad6afbd58e080a9eb86638" ), "spaces" : "bar" , "i18n" : [ { "l" : "en" , "x" : 2 } ] }

      Original Summary

      nested projection is failing when the query is with an array field

      Original Description

      When the 'spaces' field is an array, the queries fail to project i18n.$ correctly, ('en' is always returned)
      It's maybe fixed since 3.4, but submitting it in case it's not

            Assignee:
            Unassigned Unassigned
            Reporter:
            caub Cyril Auburtin
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: