问题
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