I mix different types of images in my collection. Each document type calls for a different set of unique ids. 2D images have their own identifyeers, that they do not sharre with the identifiers for 3D images.
Here is a simplified overview of the documents in the collection :
I am trying to use $merge on this partial and unique index db.images.createIndex({'type': 1, '3DimageID': 1},{ partialFilterExpression: { 'type': '3D' }, unique : true})
But get this error: OperationFailure: Cannot find index to verify that join fields will be unique, full error: {'operationTime': Timestamp(1639405564, 1), 'ok': 0.0, 'errmsg': 'Cannot find index to verify that join fields will be unique', 'code': 51183, 'codeName': 'Location51183', '$clusterTime': {'clusterTime': Timestamp(1639405564, 1), 'signature': {'hash': b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 'keyId': 0}}}
It forces us to edit the document before we are able to insert into our environment. Leave _id out or publish real ids. It help us help you and help more people because it is more efficient time wise.
Since your partialFilterExpression specifies type:3D, having type:1 in your index is redundant and wasteful space wise. I would only specify 3DmageID in the index.
Thanks Steeve, and sorry about the _ids, as I’m working with patient data, I’m always (too) cautious.
Actually, the Index creation is not a problem, rather, the $merge pipeline stage refuses to use the created index, altough unique, to perform the merge operation.
I finally found out that partial unique index is not enough, although it wasn’t specified in the official documentation (see the documentation clarification request from MongoDb dev here : https://jira.mongodb.org/browse/DOCS-14827 )