From 0535f5e963d01ef44b053ad58ef2f713ac60c07f Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 20 Jan 2023 19:08:34 +0300 Subject: [PATCH] inc --- mongo.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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()