Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-945

field.$ projection failing when the query contains an array field

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: MongoDB 3.2
    • Environment:
      windows 10
      mongo 3.2.10

      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

      > 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 } ] }
      
      > 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 } ] }
      

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

              Created:
              Updated:
              Resolved: