async def put(self, obj: KVPair) -> Tuple[Optional[KVPair], KVPair]: if old_doc := (await self.collections.find_one({"key": obj.key})): await self.collections.replace_one({"_id": old_doc["_id"]}, obj.dump()) return KVPair.load(old_doc), obj
async def get(self, key: str) -> KVPair: doc: dict = await self.collections.find_one({"key": key}) return KVPair.load(doc) if doc else None
async def has_field(self, field: str) -> AsyncGenerator[KVPair, None]: async for doc in self.collections.find({field: {"$exists": True}}): yield KVPair.load(doc)
async def iter(self) -> AsyncGenerator[KVPair, None]: async for doc in self.collections.find(): yield KVPair.load(doc)