Вопрос

is it possible to use custom _id fields with Django and MongoEngine? The problem is, if I try to save a string to the _id field it throws an Invalid ObjectId eror. What I want to do is using my own Id's. This never was a problem without using Django because I caught the DuplicateKeyError on creation if a given id was already existing (which was even necessary to tell the program, that this ID is already taken) Now it seems as if Django/MongoEngine won't even let me create a custom _id field :-/ Is there any way to work arround this without creating a second field for the ID and let the _id field create itself?

Greetings Codehai

Это было полезно?

Решение

You can set the parameter primary_key=True on a Field. This will make the target Field your _id Field.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top