[DOCS-4372] Document distinct()'s behavior when field is an array Created: 15/Oct/14  Updated: 13/Nov/23  Resolved: 20/Feb/15

Status: Closed
Project: Documentation
Component/s: manual
Affects Version/s: None
Fix Version/s: v1.3.18, Server_Docs_20231030, Server_Docs_20231106, Server_Docs_20231105, Server_Docs_20231113

Type: Improvement Priority: Minor - P4
Reporter: Ranjith Ramachandra Assignee: Kay Kim (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:
Days since reply: 8 years, 51 weeks, 6 days ago

 Description   

When there is an array field in the records and a distinct query is performed on that field, the return is not an array of arrays. The behaviour is not documented anywhere and is quite counter-intuitive.

I would expect an array of arrays. Even if it is not the case there should at least be some documentation about this beahaviour



 Comments   
Comment by Githook User [ 20/Feb/15 ]

Author:

{u'username': u'kay-kim', u'name': u'kay', u'email': u'kay.kim@10gen.com'}

Message: DOCS-4372 distinct and array fields
Branch: v2.4
https://github.com/mongodb/docs/commit/a74112d69cd960b68e9870714e6db91914fb6c8a

Comment by Githook User [ 20/Feb/15 ]

Author:

{u'username': u'kay-kim', u'name': u'kay', u'email': u'kay.kim@10gen.com'}

Message: DOCS-4372 distinct and array fields
Branch: v2.6
https://github.com/mongodb/docs/commit/de6a0f3b51eae724981c61532d37c79c2da4d07e

Comment by Githook User [ 20/Feb/15 ]

Author:

{u'username': u'kay-kim', u'name': u'kay', u'email': u'kay.kim@10gen.com'}

Message: DOCS-4372 distinct and array fields
Branch: master
https://github.com/mongodb/docs/commit/b4212a953e4cfc7512c6fda2f576b856f0b530dc

Comment by Ramon Fernandez Marina [ 14/Nov/14 ]

Hi ranjith19,

when the distinct() field is an array, each element of the array is considered a distinct value. Here's another example similar to yours that illustrates this behavior:

> db.foo.insert({a:1, b:[[1,2],[3,4]]})
> db.foo.insert({a:2, b:[[5,6],[7,8]]})
> db.foo.distinct('a')
[ 1, 2 ]
> db.foo.distinct('b')
[ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ], [ 7, 8 ] ]

You're right about the documentation part, so I'm moving this ticket to the DOCS project so the documentation can be enhanced.

Comment by Ranjith Ramachandra [ 12/Nov/14 ]

What is the status on this bug?

Generated at Thu Feb 08 07:47:50 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.