code: def upsert(self, null=False):
          
          self._pre_save()
          self.validate()
  
          filter_ = self._upsert_filter()
          if filter_:
              update = self._upsert_update(filter_, null)
  
              if update['$set']:
                  r = self._coll.find_one_and_update(filter_, update,
                                                     upsert=True, new=True)
                  self._data['_id'] = r['_id']
          else:
              r = self._coll.insert_one(self._data)
              self._data['_id'] = r.inserted_id
docs: Insert or Update Document
  
          :param null: whether update null values
          Wisely select unique field values as filter,
          Update with upsert=True