Suppose I have this function:
def insert_data(self, data, id):
self.snapshots.update_one({'snapshot_id': id},
{'$set': {'topic': data}}, upsert=True)
data is always a dictionary with a single entry (one key-value pair). each time this function is called, 'data' holds a different key. I want each call to add that key-value pair under 'topic'.
Let's say data is {1:2} at the first call and {3:4} at the second. I want to have {'topic': {1:2, 3:4}} after the two calls. How do I achieve that? The function above overwrites the data dictionary, so only the last one remains (at this case I end up with {'topic': {3:4}}).
It must not be that complicated but I was unable to get it to work properly.