[Fixed]-Retrieve mongodb documents with int as _id

1👍

With MongoEngine, you can define a field in your document as the “primary key” ( “_id” field by using primary_key in the keyword arguments to the field:

class MyClass(Document):
    id = IntField(primary_key=True)

But of course you need to make sure that “type” is used everywhere in your collection otherwise the type checking will fail for any “_id” that is not an int().

Leave a comment