$merge doesn't always ensure unique index existence.

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Optimization
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Currently $merge checks ensureFieldsUniqueOrResolveDocumentKey at creation time only if an explicit on field is passed. If an explicit on field is not passed then the implied on field is either _id in the case that the collection is unsharded or shardKey + _id in the case that it is sharded. The code assumes the existence of the (shardKey +) _id index which is not true if autoIndexId = false is specified at collection creation time.

      We discovered this because viewless timeseries collections were making it all the way to the insert step despite the nonexistence of the unique index indicating that no other existence check is being performed for the unique index. Searching the codebase for references to ensureFieldsUniqueOrResolveDocumentKey using a language server also reveals no references outside of creation/parse time. We plan on resolving the unsharded case as part of SERVER-107433. This ticket is only intended to track the investigation of the sharded case.

            Assignee:
            Unassigned
            Reporter:
            Sam Mercier
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: