I have documents in the form:
{"hostname": "myhost1.com", "services": { ... } }
What I'd like to do is the following:
dataset = requests.get('http://endpoint.com/hardware.json').json()
for hostname, services in dataset[0].items():
db.titleHardware.update_one({'hostname':hostname},
{services.keys()[0]: services.values()[0]},
True) #upsert
However, I'm getting the following error:
ValueError: update only works with $ operators
Is there a way to accomplish this update of the entire "services"
chunk, based on the "hostname"
key (and ultimately, inserting a new document if hostname
doesn't exist)? I know I can write logic to compare what's in my MongoDB with what I'm trying to update/insert, but I was hopeful that there may be something already in pymongo
or something that I could use for this.