
NOTICE: All information contained herein is, and remains
the property of TechnoCore.
The intellectual and technical concepts contained
herein are proprietary to TechnoCore and dissemination of this information or reproduction of this material
is strictly forbidden unless prior written permission is obtained
from TechnoCore.
ObjDataMongoThe ObjDataMongo class provides a suite of methods for interacting with a MongoDB database. It serves as a high-level abstraction layer, simplifying common MongoDB operations such as connecting, querying, and data manipulation.
ObjDataMongo is designed to be a robust and easy-to-use interface for MongoDB. It handles connection management, authentication, and provides a set of intuitive methods for common database tasks.
Key functionalities include:
mongo_connect()Establishes a connection to the MongoDB instance using credentials from the global configuration. It initializes global connectors and verifies authentication.
Returns True on a successful connection, False otherwise.
mongo_get_query(query_str)Parses a MongoDB aggregation query string to extract the collection name and the pipeline.
query_str (str): The MongoDB aggregation query string (e.g., db.collection.aggregate([...])).Returns a tuple (collection_name, pipeline_string).
mongo_index(collection_name, index_name)Creates an index on a specified collection.
collection_name (str): The name of the collection.index_name (str): The name of the field to index.mongo_insert(collection_name, content)Inserts one or more documents into a collection.
collection_name (str): The name of the collection.content (dict or list): A single document (dictionary) or a list of documents to insert.Returns True on success, False on failure.
mongo_update(collection_name, content)Updates a single document in a collection. The document is identified by its _id, guid, or Guid.
collection_name (str): The name of the collection.content (dict): The document content to update. Must include the identifier field.Returns True on success, False on failure.
mongo_replace(collection_name, content)Replaces a document in a collection. If the document does not exist, it is inserted.
collection_name (str): The name of the collection.content (dict): The document to replace or insert.mongo_pipeline(collection_name, pipe_line)Executes a MongoDB aggregation pipeline.
collection_name (str): The name of the collection to run the pipeline on.pipe_line (list): A list of aggregation pipeline stages.Returns a list of documents resulting from the aggregation.
mongo_get_dict(collection_name, key, value)Retrieves a single document from a collection that matches a query.
collection_name (str): The name of the collection.key (str or dict): The field to query by, or a full query dictionary.value (str): The value to match if key is a string.Returns a dictionary representing the document, or None if not found.
mongo_get_all_dicts(collection_name, key, value)Retrieves all documents from a collection that match a query.
collection_name (str): The name of the collection.key (str or dict): The field to query by, or a full query dictionary.value (str): The value to match if key is a string.Returns a cursor to the matching documents.
mongo_get_collection(collection_name)Retrieves all documents from a specified collection.
collection_name (str): The name of the collection.Returns a cursor to all documents in the collection.
mongo_get_fields_from_collection(collection_name)Samples documents from a collection to determine its schema (field names and types).
collection_name (str): The name of the collection.Returns a list of dictionaries, each describing a field.
mongo_delete(collection_name, key, value)Deletes a single document from a collection based on a key-value pair.
collection_name (str): The name of the collection.key (str): The field to query by.value (str): The value to match for deletion.