updated function to get visual communication

This commit is contained in:
Brian Bjarke Jensen
2024-03-31 12:24:49 +02:00
parent bb95e78132
commit 75b57bd28f
+8 -5
View File
@@ -1,3 +1,4 @@
"""Definition of function to get visual communication from database."""
from __future__ import annotations
import logging
@@ -18,7 +19,8 @@ def get_visual_communication(
query['annotation'] = {'$ne': None}
else:
query['annotation'] = {'$eq': None}
data = collection.aggregate([
data = collection.aggregate(
pipeline=[
{
'$match': query, # find using filters
},
@@ -27,10 +29,11 @@ def get_visual_communication(
'size': 1, # get one random
},
},
])
],
)
data_list = list(data) # read data from cursor object
if len(data_list) == 0:
logging.error('failed getting visual communication')
raise NoDocumentFoundException()
logging.info('finished')
return VisualCommunication.model_validate(data_list[0])
vis_com = VisualCommunication.model_validate(data_list[0])
logging.debug('finished')
return vis_com