{ $t: “”, $v: “”} structure in MongoDB collections using pymongo

半腔热情 提交于 2019-12-11 06:26:51

问题


I'm using pymongo libraries to upload my data into documentDB (it accepts MongoDB libraries). My json data objects (read using the json library from a json file) before sending them to my documentDB collection are in the format of (a portion of the data):

...
{
"id": [
    "{}",
    "i"
  ]
}
...

However, in the database they are stored like:

...
{
  "id": {
    "$t": 4,
    "$v": [
      {
        "$t": 2,
        "$v": "{}"
      },
      {
        "$t": 2,
        "$v": "i"
      }
    ]
  }
}
...

My python code that inserts data into MongoDB is

client = MongoClient("url")
self.__db = client["database"]
self.__db["collection"].insert_one(data)

For debugging purposes I added this line right before insert_one() statement

for k, v in data.items():
  print(k, v)

and here is the output on the console:

.. 
id ['{}', 'i'] 
..

Is there any additional parameter that I need to set on pymongo to save data as is? When I read data from the MongoDB using pymongo it handles $t, $v conversions but my data readers are not in python and don't do the conversion automatically

Update I switched to DocumentDb python library. It works just fine. I just needed to spend a couple of hours creating a new db interface for it in my app.

来源:https://stackoverflow.com/questions/43670909/t-v-structure-in-mongodb-collections-using-pymongo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!