You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When calling list_collection_names() with a filter, mongomock will list "created" and "non-created" collections as opposed to what it does when no filter is provided in which case only "created" collections are listed.
Here is a small test which exposes the isssue:
deftest_list_collection_names():
client=mongomock.MongoClient()
db=client["my_db"]
assertdb.list_collection_names() == [] # OK# Run an update operation on a non existent collectiondb["my_collection"].update_many({}, {"$set": {"a": 1}})
assertdb.list_collection_names() == [] # OKassertdb.list_collection_names(filter={"name": "my_collection"}) == [] # KO
When looking at the underlying code, mongomock relies on self._get_created_collections() when no filter is provided (here), whereas it uses self._store._collections when a filter is passed (here). I would have expected self._get_created_collections() to be used in both cases.
The current behavior does not match the one of MongoDB.
Python version: 3.9.9
mongomock version: 4.1.2
The text was updated successfully, but these errors were encountered:
Summary
When calling
list_collection_names()
with a filter, mongomock will list "created" and "non-created" collections as opposed to what it does when no filter is provided in which case only "created" collections are listed.Here is a small test which exposes the isssue:
This test produces the following output:
When looking at the underlying code, mongomock relies on
self._get_created_collections()
when no filter is provided (here), whereas it usesself._store._collections
when a filter is passed (here). I would have expectedself._get_created_collections()
to be used in both cases.The current behavior does not match the one of MongoDB.
Python version: 3.9.9
mongomock version: 4.1.2
The text was updated successfully, but these errors were encountered: