this is an upsert method: replaces or creates the DB representation of the model instance

def update(self, instance):
        """ this is an upsert method: replaces or creates the DB representation of the model instance """
        assert isinstance(instance, self.model_klass)
        if instance.db_id:
            query = {'_id': ObjectId(instance.db_id)}
        else:
            query = build_db_query(self.primary_key, instance.key)
        self.ds.update(self.collection_name, query, instance)
        return instance.db_id