I am trying to add more arrays to existing array.
Currently it's like this:
"lastmsg" : ISODate("2020-01-27T07:23:03.601Z"),
"_force_collection" : false,
"metadata" : {
"cwmpid" : "1804289383",
"current_time" : "2020-01-27T08:23:02+00:00",
"DSLInterface_parameter" : "WANDevice.1.",
I have python script that uses update_one
and $set
, but that removes existing data in metadata and adds what I need, but I want to keep already existing metadata and add new fileds without overwriting existing data.
Here is code snippet of python script:
dict = {
"metadata": {
"loc": {
"mark": row["metadata.loc.geo.bs.mark"],
"dslam": {
"locname": row["metadata.loc.geo.dslam.locname"],
"mark": row["metadata.loc.geo.dslam.mark"],
"devname": row["metadata.loc.geo.dslam.devname"],
},
"geo": {
"coordinates": [
float(
row["metadata.loc.geo.coordinates.longitude"]
),
float(row["metadata.loc.geo.coordinates.latitude"]),
],
"type": row["metadata.loc.geo.type"],
},
}
}
}
criteria = {"cpeid": cpeid}
res = mycol.update_one(criteria, {"$set": dict})
After running that it overwrites existing data, so new output looks like this:
"metadata" : {
"loc" : {
"geo" : {
"type" : "Point",
"coordinates" : [
16.4665492,
43.5076267
]
},
"dslam" : {
"locname" : "",
"devname" : "",
"mark" : "0"
},
"mark" : ""
}
}
}
What I am trying to get is this:
"lastmsg" : ISODate("2020-01-27T07:23:03.601Z"),
"_force_collection" : false,
"metadata" : {
"cwmpid" : "1804289383",
"current_time" : "2020-01-27T08:23:02+00:00",
"DSLInterface_parameter" : "WANDevice.1.",
"loc" : {
"geo" : {
"type" : "Point",
"coordinates" : [
16.4665492,
43.5076267
]
},
"dslam" : {
"locname" : "",
"devname" : "",
"mark" : "0"
},
"mark" : ""
}
}
}