Skip to content
Advertisement

pymongo converts . variables into a dict

I am inserting the data to mongoDB collection through pymongo. I have logged all the information and data which is being sent to update_one statement.

Data which is logged just before update_one statement :

JavaScript

But when it got inserted into “test” then it got appended like this :

JavaScript

Using this to update the document:

JavaScript

So here you’ll see parsed data with same prefix keys ThingName. get converted into a dict in mongo collection with key as ThingName. WHy this is happening and how can we override this?

Advertisement

Answer

That’s perfectly valid. Because when you update with thing.a:x, then it will store as object thing: { a : x}

Field names restrictions

Though mongo supports dot in latest versions, drivers do not support them yet. Hence the conversion still happens.

Another wonderful post

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement