updated function to list names of all vis com docs in database

This commit is contained in:
Brian Bjarke Jensen
2024-03-31 12:26:51 +02:00
parent 75b57bd28f
commit c3aba7831b
+7 -3
View File
@@ -1,3 +1,7 @@
"""
Definition of function to list names
of all visual communication documents in database.
"""
from __future__ import annotations from __future__ import annotations
from pymongo.collection import Collection from pymongo.collection import Collection
@@ -5,14 +9,14 @@ from pymongo.collection import Collection
def list_names( def list_names(
collection: Collection, collection: Collection,
has_annotation: bool = True, only_with_annotation: bool = True,
) -> list[str]: ) -> list[str]:
"""List the names of entries that match the filters.""" """List the names of entries that match the filters."""
assert isinstance(collection, Collection) assert isinstance(collection, Collection)
assert isinstance(has_annotation, bool) assert isinstance(only_with_annotation, bool)
# build query # build query
query = {} query = {}
if has_annotation: if only_with_annotation:
query['annotation'] = {'$ne': None} query['annotation'] = {'$ne': None}
# execute query # execute query
res_list = collection.find( res_list = collection.find(