Skip to content Skip to sidebar Skip to footer

Get The Duplicate Value On Duplicatekeyerror

In pymongo, when a DuplicateKeyError caught, what's the proper way to find out the duplicate value behind the the exception? Currently I do this try: db.coll.insert({key: ['som

Solution 1:

In dev version of pymongo (2.7) you can check with error_document property:

try:
    db.coll.insert({name: 'some_value'})
except pymongo.errors.DuplicateKeyError, e:
    print e.error_document

As far as I know, in 2.6 and earlier versions, all info except error msg and code is discarded.

Post a Comment for "Get The Duplicate Value On Duplicatekeyerror"