Skip to content

Commit

Permalink
Addded logic to check whether a collection exists.
Browse files Browse the repository at this point in the history
  • Loading branch information
develprr committed Dec 1, 2023
1 parent bea098e commit 4668d83
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/msmongoclient.py
Expand Up @@ -42,9 +42,19 @@ def find(self, collection_name, query):

def delete_many(self, collection_name, query):
return self.client[collection_name].delete_many(query)

def exists_collection(self, collection_name):
return collection_name in self.collection_names()

@cache
def collection_names(self):
return self.client.list_collection_names()

def test_insert_one():
client = MSMongoClient.singleton
client.insert_one("users", { "name": "Moctezuma" })
entry = client.find_one("users", {})
assert(entry["name"] == "Moctezuma")
assert(entry["name"] == "Moctezuma")

def test_exists_collection():
assert(MSMongoClient.singleton.exists_collection("SoccerEvent") == True)

0 comments on commit 4668d83

Please sign in to comment.