I need to keep couple of strings inside mongoDB.
I have temporary schema of document in attachment. ([login to view URL])
Need to prepare 2 python methods which will be get set of arguments (instance_id, name and guid) and create or update records inside mongo collection.
instance_id = unique instance identifier (string)
guid = id of document (string)
name = name of instance (string)
documents must be filtered thru guid, this is "ObjectId()"
Example:
def set_instance(self, instance_id, guid,instance_name):
key = self.gen_code() #My code
self.col.update_one(filter={"_id": ObjectId(guid)}, update={"$push": {"instances": {
instance_id: {
"instance_name": ,
"key": key
}
}}})
First function must create new records in document.
Second function must update existing record (instance_id) in document.
Schema could be tune if needed but only for "instances"
If you want to modify "instances" from object to array for example, YW.
At the end I want to receive 2 functional methods for set and update and good schema of document.