diff --git a/mongo.py b/mongo.py index 6b9880e..619440f 100644 --- a/mongo.py +++ b/mongo.py @@ -30,7 +30,10 @@ class Mongo: return self["counter"] def inc(self, username, chat_id): - self.counter_collection.update_one({"chat_id": chat_id, "username": username}, {"$inc": {"count": 1}}) + if self.counter_collection.find_one({"chat_id": chat_id, "username": username}): + self.counter_collection.update_one({"chat_id": chat_id, "username": username}, {"$inc": {"count": 1}}) + else: + self.counter_collection.insert_one({"chat_id": chat_id, "username": username, "count": 1}) mongo = Mongo()