I am using python 3.9.12 to query mongodb, I then read the values into variables and continue with my logic. Problem is, some of my values have keys that start with dollar sign. Here is an example of a json I get:
[
{
"_id": {
"$oid": "234876234875236752309823"
},
"createdAt": {
"$date": "2022-11-13T20:50:18.184Z"
},
"moreFields": {
"key1": "blabla1",
"key2": "blabla2",
"key3": "blabla3"
},
"entityId": {
"$binary": {
"base64": "z0kWDTHiSlawpI2wHjyrWA==",
"subType": "04"
}
}
}
]
I understand that those mongodb field types (bson, datetime...). But this makes my life hard in trying to access those values using python.
I was reading and looking but I couldn't find a method to convert them to "normal" keys. Ideally I would want to correct my mongodb query (get datetime as strings and $binary as UUID strings). I have found a stupid workaround in python but unfortunately it is very stupid and I want to correct my ways.
Any ideas? Thanks :)
I would really be happy if the result of my mongodb query would change to:
[
{
"_id": "234876234875236752309823",
"createdAt": "2022-11-13T20:50:18.184Z",
"moreFields": {
"key1": "blabla1",
"key2": "blabla2",
"key3": "blabla3"
},
"entityId": "e87b22b2-ea15-4176-9100-c65f79f0e5b2"
}
]