async_mongo_client
Asynchronous MongoDB client implementation for the SKA SRC API Global Execution service.
Module Contents
Classes
Repository for MongoDB operations. |
Attributes
- class async_mongo_client.AsyncMongo(host=__MONGO_HOST, port=__MONGO_PORT, username=__MONGO_USERNAME, password=__MONGO_PASSWORD, db_name=__MONGO_DATABASE)
Repository for MongoDB operations.
- __MONGO_DATABASE
- __MONGO_HOST
- __MONGO_PASSWORD
- __MONGO_PORT
- __MONGO_USERNAME
- logger
- async __client()
Get the MongoDB client instance.
- async __get_collection(collection_name)
Get a collection from the MongoDB database.
- async __setup_client(host, port, username, password, db_name)
Set up the MongoDB client.
- static __transform_from_dict(model_class, data)
Converts a MongoDB dictionary into a Pydantic model. Maps ‘_id’ back to ‘id’.
- static __transform_into_dict(model)
Transform the provided data into a dictionary format suitable for MongoDB operations. :param model: :return: A dictionary representation of the provided data.
- close()
Close the MongoDB client connection.
- async delete_many(collection_name, criteria)
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.
- async delete_one(collection_name, criteria)
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.
- async find_many(collection_name, criteria, model_class=None)
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.
- async find_one(collection_name, criteria, model_class=None)
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.
- async insert_many(collection_name, documents)
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.
- async insert_one(collection_name, document)
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.
- async ping()
- async replace_many(collection_name, criteria, replacement_data)
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.
- async replace_one(collection_name, criteria, replacement_data)
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.
- async update_many(collection_name, criteria, update_data)
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.
- async update_one(collection_name, criteria, update_data)
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.
- async upsert_one(collection_name, metadata_filter, data)
Upsert a document in the specified collection based on the provided filter and data.
- Parameters:
collection_name – The name of the collection to upsert the document in.
metadata_filter – The filter to identify the document to update or insert.
data – The data to update or insert in the document.
- Returns:
A boolean indicating whether the upsert operation was acknowledged by MongoDB.
- async_mongo_client.T