[SERVER-60104] $merge not working with partial index Created: 21/Sep/21 Updated: 27/Oct/23 Resolved: 28/Sep/21 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | 4.4.8 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Wernfried Domscheit | Assignee: | Edwin Zhou |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | aggregation-framework, index, merge, partial | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
|||||||||||||||||||||||||||||||||||||||
| Operating System: | ALL | |||||||||||||||||||||||||||||||||||||||
| Steps To Reproduce: |
|
|||||||||||||||||||||||||||||||||||||||
| Participants: | ||||||||||||||||||||||||||||||||||||||||
| Description |
|
I have two collections where I like to run an aggregation pipeline with $merge. However, the target collection has a partial unique index. According documentation $merge also works with spare indexes, so I would assume a partial index should also work. |
| Comments |
| Comment by Edwin Zhou [ 29/Sep/21 ] | |||||||||||||||||||||||||||||||||||||||||
|
Hi wernfried.domscheit@sunrise.net, Thank you for following up. We no longer take feature suggestions for MongoDB on the SERVER project, but you may submit your ideas for improvements over on our UserVoice. Best, | |||||||||||||||||||||||||||||||||||||||||
| Comment by Wernfried Domscheit [ 29/Sep/21 ] | |||||||||||||||||||||||||||||||||||||||||
|
Hi Edwin
Sorry, I did a typo. Of course, the aggregation pipeline must be this:
Anyway, maybe you consider to support partial indexes in future releases of MongoDB. For example one of these:
Kind Regards
| |||||||||||||||||||||||||||||||||||||||||
| Comment by Edwin Zhou [ 28/Sep/21 ] | |||||||||||||||||||||||||||||||||||||||||
|
Hi wernfried.domscheit@sunrise.net, Thanks for reporting this issue! Specifying "on" when using $merge requires a unique index with keys that correspond to the on identifier fields. When specifying a partial index, the unique constraint is only applicable to the documents that meet the filter expression. This unique constraint doesn't prevent documents from being inserted if it doesn't meet the filter criteria. This behavior works as designed. While this is made explicit in our source code, I think this can be clarified in our documentation, so I've filed Best, |