When PyMongo throws a DuplicateKeyError How can I tell what field caused the conflict?

40 Views Asked by At

Using Ming and PyMongo I have created several documents with more than one unique index. If a DuplicateKeyError is thrown, then I want to query for the conflicting document. Is there a way for me to take a DuplicateKeyError exception and know what field (or combination of fields) generated the exception?

This is not a duplicate because the error document is not always returned with .details (The 2.8 version of .error_document). Its my understanding it might be included. There is no guarantee. In my case .details is returning None when the duplicate key is thrown.

0

There are 0 best solutions below