def upsert(self, null=False):
self._pre_save()<EOL>self.validate()<EOL>filter_ = self._upsert_filter()<EOL>if filter_:<EOL><INDENT>update = self._upsert_update(filter_, null)<EOL>if update['<STR_LIT>']:<EOL><INDENT>r = self._coll.find_one_and_update(filter_, update,<EOL>upsert=True, new=True)<EOL>self._data['<STR_LIT>'] = r['<STR_LIT>']<EOL><DEDENT><DEDENT>else:<EOL><INDENT>r = self._coll.insert_one(self._data)<EOL>self._data['<STR_LIT>'] = r.inserted_id<EOL><DEDENT>
Insert or Update Document

        :param null: whether update null values
        Wisely select unique field values as filter,
        Update with upsert=True