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

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

    XMLWordPrintable

    Details

    • Type: Question
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: MongoDB 3.2
    • Labels:
      None
    • Environment:
      windows 10
      mongo 3.2.10

      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

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

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved: