diff --git a/asab/storage/mongodb.py b/asab/storage/mongodb.py index 1fa13dfb..90e09e14 100644 --- a/asab/storage/mongodb.py +++ b/asab/storage/mongodb.py @@ -174,7 +174,6 @@ async def execute(self, custom_data: typing.Optional[dict] = None, event_type: t if self.Version is not None: filtr['_v'] = int(self.Version) - # First wave (adding stuff) if len(addobj) > 0: coll = self.Storage.Database[self.Collection] try: @@ -194,6 +193,13 @@ async def execute(self, custom_data: typing.Optional[dict] = None, event_type: t # Object might have been changed in the meantime raise KeyError("NOT-FOUND") + if ret.get('_v') == 1 and '_c' not in ret: + # If the object is new (version is 1), set the creation datetime + await coll.update_one( + { id_name: ret[id_name] }, + { '$set': { '_c': ret['_m'] } } + ) + self.ObjId = ret[id_name] if self.Storage.WebhookURIs is not None: