[SERVER-37198] Add tests for $arrayToObject behaviour when two keys are identical Created: 19/Sep/18  Updated: 06/Dec/22  Resolved: 12/Oct/18

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: Jakub Szypulka Assignee: Backlog - Query Team (Inactive)
Resolution: Duplicate Votes: 0
Labels: aggregation-framework, test, testing, tests
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-37182 Different values when referencing who... Closed
Assigned Teams:
Query
Participants:

 Description   

According to the documentation, when $arrayToObject is used on an array where some keys repeat, the value of the first key is used.

However, as far as I can see, this behaviour is not being tested for in the jstests integration test.

I propose adding the following test to jstests/aggregation/expressions/arrayToObject.js:

    // check that if two keys are equal, the value of the first key is used
    assert.writeOK(coll.insert({_id: 26, expanded: [["same", 1], ["same", 2]]}));
    result = coll.aggregate([{$match: {_id: 26}}, array_to_object_expr]).toArray();
    assert.eq(result, [{_id: 26, collapsed: {"same": 1}}]);

 



 Comments   
Comment by Ian Boros [ 12/Oct/18 ]

Hi jaksz. Thanks for your pull request! Fortunately a test similar to yours was committed as part of SERVER-37182. Here's a link to the new test.

Comment by David Storch [ 12/Oct/18 ]

ian.boros, can you take a look at the linked pull request? This relates to your work in SERVER-37182. jaksz, I believe Ian may have already added a test such as the one proposed in Pull Request #1259. However, if there is still a gap in coverage Ian can review and merge your changes. Thanks!

Comment by Nick Brewer [ 19/Sep/18 ]

jaksz Thanks for your contribution. I'm leaving this ticket open for now - we'll revisit it based on the outcome of SERVER-37182.

-Nick

Comment by Jakub Szypulka [ 19/Sep/18 ]

GitHub Pull Request

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