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

$ projection does not support queries on multiple array fields

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Works as Designed
    • 3.2.10
    • None
    • Querying
    • 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 } ] }

    Description

      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

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: