[SERVER-31343] Distinct over empty indexed arrays produces undefined value in the result Created: 30/Sep/17  Updated: 07/Nov/17  Resolved: 30/Sep/17

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 3.4.9
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Slavi Pantaleev Assignee: Kelsey Schubert
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-14832 Distinct command result set may inclu... Needs Scheduling
Operating System: ALL
Steps To Reproduce:

> db.testcol.insert({"someArray": ["1"]});
WriteResult({ "nInserted" : 1 })
> db.testcol.insert({"someArray": ["2"]});
WriteResult({ "nInserted" : 1 })
> db.testcol.insert({"someArray": []});
WriteResult({ "nInserted" : 1 })
> 
> db.testcol.distinct("someArray")
[ "1", "2" ]
>
> 
> db.testcol.ensureIndex({"someArray": 1})
{
	"createdCollectionAutomatically" : false,
	"numIndexesBefore" : 1,
	"numIndexesAfter" : 2,
	"ok" : 1
}
> 
> db.testcol.distinct("someArray")
[ undefined, "1", "2" ]

Participants:

 Description   

When using the distinct command targeting an indexed array field, which also happens to be empty, an additional `undefined` value is added to the result.

If there is no index on the field, it's correct - there is no `undefined` value in the result.



 Comments   
Comment by Kelsey Schubert [ 30/Sep/17 ]

Hi s.pantaleev,

Thank you for the detailed report with clear reproduction steps. We're able to reproduce this issue and are tracking it in SERVER-14832. Please feel free to vote for SERVER-14832 and watch it for updates.

Kind regards,
Kelsey

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