[SERVER-27644] distinct on a view doesn't "flatten" array members Created: 11/Jan/17  Updated: 16/Mar/21  Resolved: 07/Feb/17

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: 3.4.1, 3.5.1
Fix Version/s: 3.4.4, 3.5.3

Type: Bug Priority: Major - P3
Reporter: Asya Kamsky Assignee: Kyle Suarez
Resolution: Done Votes: 0
Labels: read-only-views
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Related
related to SERVER-27484 allow $setUnion in $group Closed
is related to SERVER-55112 Behaviour of distinct differs between... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Completed:
Backport Requested:
v3.4
Sprint: Query 2017-02-13
Participants:

 Description   

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 ]



 Comments   
Comment by Githook User [ 14/Apr/17 ]

Author:

{u'username': u'ksuarz', u'name': u'Kyle Suarez', u'email': u'kyle.suarez@mongodb.com'}

Message: SERVER-27644 $unwind arrays when performing distinct on a view

(cherry picked from commit 3ed956d8813b7b56c2319456c28838dfa6c5c20b)

Conflicts:
src/mongo/db/query/parsed_distinct_test.cpp
Branch: v3.4
https://github.com/mongodb/mongo/commit/fb73656e7d384ae22d4a615af0cba8bc865b2bff

Comment by Githook User [ 07/Feb/17 ]

Author:

{u'username': u'ksuarz', u'name': u'Kyle Suarez', u'email': u'kyle.suarez@mongodb.com'}

Message: SERVER-27644 $unwind arrays when performing distinct on a view
Branch: master
https://github.com/mongodb/mongo/commit/3ed956d8813b7b56c2319456c28838dfa6c5c20b

Comment by Kyle Suarez [ 11/Jan/17 ]

A fix for this also needs to update jstests/core/views/views_distinct.js to run tests on documents with more complicated schemas (arrays definitely, and maybe nested objects and nullish values).

Generated at Thu Feb 08 04:15:45 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.