{
"_id": {
"$oid": "65ea05dbaa907e05219c0934"
},
"id": 6,
"title": "asd",
"content": "asd",
"author": "asd",
"category": "asd",
"createdAt": {
"$date": "2024-03-07T20:21:52.000Z"
}
}
I couldn’t find the answer to the question on the Internet and gpt
2
Answers
Please share more details about how this record is created.
For posterity. The
_id
field is created by the MongoDB server and used by the server so you cannot delete that by default. It is 12 bit binary data.Nevertheless, this is not what the OP asked.
Djongo mimics Django’s ORM and so just like in Django, an
AutoField
(AUTOINCREMENT field) is implicitly added to your models. This is theid
field you automatically get.But if you explicitly add an
ObjectIdField
(internally setsprimary_key
asTrue
), the implicitly createdAutoField
(AUTOINCREMENT field) will not be added.Fun fact: using the
ObjectIdField
in your models will save you from calling Django migrations every time you create a new model.