I have a database ‘Product’. Which contains a collection name ‘ProductLog’. Inside this collection , there are 2 documents in the following format:
{
"environment": "DevA",
"data": [
{
"Name": "ABC",
"Stream": "Yes"
},
{
"Name": "ZYX",
"Stream": "Yes"
}
]
},
{
"environment": "DevB",
"data": [
{
"Name": "ABC",
"Stream": "Yes"
},
{
"Name": "ZYX",
"Stream": "Yes"
}
]
}
This gets added as 2 documents in collection. I want to append more data in the already existing document’s ‘data’ field in MongoDB using python. Is there a way for that? I guess update would remove the existing fields in "data" field or may update a whole document.
For example: Adding one more array in EmployeeDetails
field, while the earlier data in EmployeeDetail
also remains.
2
Answers
There is a SQL library in Python language through which you can insert/add your data in your desired database. For more information, check out the tutorial
I want to show how you can append more data in the already existing document ‘data’ field in MongoDB using python:
First install pymongo:
Now let’s get our hands dirty: