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

distinct on a view doesn't "flatten" array members

    • Fully Compatible
    • ALL
    • v3.4
    • Query 2017-02-13

      If you create an identity view on a collection which has some field that contains an array, the result of db.collection.distinct("thatfield") and db.identityview.distinct("thatfield") will not be the same.

      db.coll.find()
      { "_id" : ObjectId("5876aaed34e6e16cd498d61c"), "a" : 1 }
      { "_id" : ObjectId("5876aaf034e6e16cd498d61d"), "a" : [ 2 ] }
      { "_id" : ObjectId("5876aaf734e6e16cd498d61e"), "a" : [ 3, 4 ] }
      db.coll.distinct("a")
      [ 1, 2, 3, 4 ]
      db.createView("view","coll",[])
      { "ok" : 1 }
      agg@127.0.0.1:27017(3.4.1) > db.view.distinct("a")
      [ [ 3, 4 ], [ 2 ], 1 ]
      

            Assignee:
            kyle.suarez@mongodb.com Kyle Suarez
            Reporter:
            asya.kamsky@mongodb.com Asya Kamsky
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: