def create(self):
"""Creates model in database."""
state = self.get_state()
state.pop("_id", None)
state["time"]["created"] = timeutils.current_unix_timestamp()
state["time"]["updated"] = state["time"]["created"]
state["update_marker"] = self.new_update_marker()
collection = self.collection()
insert_method = retryutils.mongo_retry()(collection.insert_one)
find_method = retryutils.mongo_retry()(collection.find_one)
try:
document = insert_method(state)
except pymongo.errors.DuplicateKeyError as exc:
raise exceptions.UniqueConstraintViolationError from exc
document = find_method({"_id": document.inserted_id})
self.set_state(document)
return self
评论列表
文章目录