In order to apply a contact information update, we use the $set update operator. As you recall, updates are performed using entity classes as an argument. Accordingly, it makes sense to use the entity class to create its own update document. Therefore, we add a method called getUpdateDoc() to the booksomeplace.entity.base.Base class, as shown here:
class Base(dict) :
def getUpdateDoc(self) :
doc = {}
for key, value in self.fields.items() :
doc.update({'$set' : {key : self[key]}})
return doc
# other methods not shown
We then add a method called edit() to booksomeplace.domain.property.PropertyService that accepts a property entity as an argument. In order to perform the update, it calls the inherited getUpdateDoc() method:
def edit(self, prop) :
query = {'propertyKey' : prop.getKey()}
return self.collection.update_one(query, prop.getUpdateDoc())
Next,...