[SERVER-29789] $setUnion returns values from second array instead of union Created: 22/Jun/17 Updated: 27/Oct/23 Resolved: 06/Jul/17 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Querying |
| Affects Version/s: | 3.2.3 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | anatolii petruchok | Assignee: | Mark Agarunov |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Operating System: | ALL |
| Steps To Reproduce: | execute script |
| Participants: |
| Description |
|
When execute either returns: "b", "a", "a", "d" 1. union does not work. expected result for union should include: "c", "b", "a", "d" |
| Comments |
| Comment by Mark Agarunov [ 06/Jul/17 ] | ||||||
|
Hello apetruc@gmail.com, Thank you for the response. As $setUnion is an aggregation operation, it can only be used inside the aggregation pipeline. When attempting it use it directly in the shell, it is not actually being parsed as an operation, but as an empty/null variable with the name $setUnion. Essentially what the shell is evaluating becomes:
Since object properties cannot have the same name, it evaluates to the last value and returns just
The second example evaluates to:
Which then simplifies to:
As this is properly working when used in the aggregation pipeline, I do not see anything to indicate a bug in the MongoDB server. For MongoDB-related support discussion please post on the mongodb-user group or Stack Overflow with the mongodb tag. A question like this involving more discussion would be best posted on the mongodb-user group. Thanks, | ||||||
| Comment by anatolii petruchok [ 06/Jul/17 ] | ||||||
|
Hi, your code works as you described. However //Run only this code //Run only this code | ||||||
| Comment by Kelsey Schubert [ 22/Jun/17 ] | ||||||
|
Could you clarify the steps you're taking to reproduce this issue? If possible, could you upload a script that shows this behavior? I was unable to observe the issue describe by the taking the steps below:
Thanks for your help, | ||||||
| Comment by anatolii petruchok [ 22/Jun/17 ] | ||||||
|
same for version 3.2.9 |