When querying MongoDB using mongoengine
it returns result with minor differences to what I expect. One of the important ones is $oid
which is returned but I don't like it:
"_id": {
"$oid": "5e3c0f7f284137537bf7c994"
},
Is there a way to project differently in mongoengine
? What I want is a simple id field:
"id": "5e3c0f7f284137537bf7c994"
EDIT1:
When I want to get string version of ID
I can use .id
to get let's say "5e3c0f7f284137537bf7c994"
. But problem is where I want to get the whole document:
MyModel.objects.all()
This query returns a list of all documents from MyModel
, BUT list of documents contain $oid
rather than string version of _id
. How should I get _id as is NOT $oid.
.id
should return string id by default – Valijon.Class.objects.get(condition).id
? – ValijonEDIT1
section of question. Thanks. – Alireza