31 lines
643 B
Python
Executable File
31 lines
643 B
Python
Executable File
from __future__ import annotations
|
|
|
|
import logging
|
|
|
|
from pymongo.collection import Collection
|
|
|
|
from shared.mongodb.src.classes import ModelData
|
|
|
|
|
|
def upsert_annotation(
|
|
collection: Collection,
|
|
vis_com_name: str,
|
|
annotations: ModelData,
|
|
) -> None:
|
|
"""Upserts annotation data in the database."""
|
|
query = {
|
|
'name': vis_com_name,
|
|
}
|
|
update = {
|
|
'$set': {
|
|
'annotation': annotations.model_dump(),
|
|
},
|
|
}
|
|
res = collection.update_one(
|
|
filter=query,
|
|
update=update,
|
|
upsert=True,
|
|
)
|
|
logging.info('upserted document: %s', res)
|
|
logging.info('finished')
|