:py:mod:`async_mongo_client` ============================ .. py:module:: async_mongo_client .. autoapi-nested-parse:: Asynchronous MongoDB client implementation for the SKA SRC API Global Execution service. Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: async_mongo_client.AsyncMongo Attributes ~~~~~~~~~~ .. autoapisummary:: async_mongo_client.T .. py:class:: AsyncMongo(host = __MONGO_HOST, port = __MONGO_PORT, username = __MONGO_USERNAME, password = __MONGO_PASSWORD, db_name = __MONGO_DATABASE) Repository for MongoDB operations. .. py:attribute:: __MONGO_DATABASE .. py:attribute:: __MONGO_HOST .. py:attribute:: __MONGO_PASSWORD .. py:attribute:: __MONGO_PORT .. py:attribute:: __MONGO_USERNAME .. py:attribute:: logger .. py:method:: __client() :async: Get the MongoDB client instance. .. py:method:: __get_collection(collection_name) :async: Get a collection from the MongoDB database. .. py:method:: __setup_client(host, port, username, password, db_name) :async: Set up the MongoDB client. .. py:method:: __transform_from_dict(model_class, data) :staticmethod: Converts a MongoDB dictionary into a Pydantic model. Maps '_id' back to 'id'. .. py:method:: __transform_into_dict(model) :staticmethod: Transform the provided data into a dictionary format suitable for MongoDB operations. :param model: :return: A dictionary representation of the provided data. .. py:method:: close() Close the MongoDB client connection. .. py:method:: delete_many(collection_name, criteria) :async: Delete multiple documents from the specified collection that match the provided filter. :param collection_name: The name of the collection to delete the documents from. :param criteria: The filter to identify the documents to delete. :return: A boolean indicating whether the delete operation was acknowledged by MongoDB. .. py:method:: delete_one(collection_name, criteria) :async: Delete a single document from the specified collection that matches the provided filter. :param collection_name: The name of the collection to delete the document from. :param criteria: The filter to identify the document to delete. :return: A boolean indicating whether the delete operation was acknowledged by MongoDB. .. py:method:: find_many(collection_name, criteria, model_class = None) :async: Find multiple documents in the specified collection that match the provided filter. :param collection_name: The name of the collection to search for the documents. :param criteria: The filter to identify the documents to find. :param model_class: Optional Pydantic model class to transform the results into. :return: A list of documents that match the filter, or an empty list if no documents are found. .. py:method:: find_one(collection_name, criteria, model_class = None) :async: Find a single document in the specified collection that matches the provided filter. :param collection_name: The name of the collection to search for the document. :param criteria: The filter to identify the document to find. :param model_class: Optional Pydantic model class to transform the result into. :return: The document that matches the filter, or None if no document is found. .. py:method:: insert_many(collection_name, documents) :async: Insert multiple documents into the specified collection. :param collection_name: The name of the collection to insert the documents into. :param documents: A list of documents to be inserted. :return: A boolean indicating whether the insert operation was acknowledged by MongoDB. .. py:method:: insert_one(collection_name, document) :async: Insert a single document into the specified collection. :param collection_name: The name of the collection to insert the document into. :param document: The document to be inserted. :return: A boolean indicating whether the insert operation was acknowledged by MongoDB. .. py:method:: ping() :async: .. py:method:: replace_many(collection_name, criteria, replacement_data) :async: Replace multiple documents in the specified collection that match the provided filter. :param collection_name: The name of the collection to replace the documents in. :param criteria: The filter to identify the documents to replace. :param replacement_data: The data to replace the documents with. :return: A boolean indicating whether the replace operation was acknowledged by MongoDB. .. py:method:: replace_one(collection_name, criteria, replacement_data) :async: Replace a single document in the specified collection that matches the provided filter. :param collection_name: The name of the collection to replace the document in. :param criteria: The filter to identify the document to replace. :param replacement_data: The data to replace the document with. :return: A boolean indicating whether the replace operation was acknowledged by MongoDB. .. py:method:: update_many(collection_name, criteria, update_data) :async: Update multiple documents in the specified collection that match the provided filter. :param collection_name: The name of the collection to update the documents in. :param criteria: The filter to identify the documents to update. :param update_data: The data to update in the documents. :return: A boolean indicating whether the update operation was acknowledged by MongoDB. .. py:method:: update_one(collection_name, criteria, update_data) :async: Update a single document in the specified collection that matches the provided filter. :param collection_name: The name of the collection to update the document in. :param criteria: The filter to identify the document to update. :param update_data: The data to update in the document. :return: A boolean indicating whether the update operation was acknowledged by MongoDB. .. py:method:: upsert_one(collection_name, metadata_filter, data) :async: Upsert a document in the specified collection based on the provided filter and data. :param collection_name: The name of the collection to upsert the document in. :param metadata_filter: The filter to identify the document to update or insert. :param data: The data to update or insert in the document. :return: A boolean indicating whether the upsert operation was acknowledged by MongoDB. .. py:data:: T