mongo.adapter Documentation
Overview
The mongo.adapter is an integration component designed to interact with MongoDB databases. It provides a structured way to perform read and write operations, manage collections, and introspect schemas. This adapter utilizes a MongoDB connection manager for handling database operations.
Purpose
The primary purpose of the mongo.adapter is to enable seamless interaction with MongoDB databases within the Vantage analytics platform. It allows users to:
- Connect and authenticate with a MongoDB database.
- Perform CRUD (Create, Read, Update, Delete) operations easily.
- Retrieve metadata regarding collections and documents.
- Handle errors during database operations effectively.
Settings
Connection Settings
-
username- Input Type: String
- Description: The username for authenticating with the MongoDB database. Changing this value will affect the authentication process.
- Default Value: None (must be provided).
-
password- Input Type: String
- Description: The password corresponding to the provided username for database authentication. It impacts successful connection; any incorrect value will prevent access.
- Default Value: None (must be provided).
-
host- Input Type: String
- Description: The hostname or IP address of the MongoDB server. Modifying this value allows the adapter to connect to a different MongoDB instance.
- Default Value:
localhost.
-
port- Input Type: Numeric
- Description: The port number the MongoDB server listens on. Changing this impacts where the adapter connects. Standard MongoDB uses port 27017.
- Default Value:
27017.
-
databaseName- Input Type: String
- Description: The name of the database to connect to. This determines which database operations will be performed. If changed, ensure the specified database exists.
- Default Value: None (must be provided).
-
ssl- Input Type: Boolean
- Description: Indicates whether to use an SSL connection to the MongoDB server. Setting this to true enables secure connections, which can be necessary for production environments.
- Default Value:
false.
How it Works
The mongo.adapter class establishes a connection to a MongoDB server using the provided settings. The connection is initiated through a URI composed of the host, port, username, and password. Upon successful connection, the adapter can perform various database operations.
Key functionalities include:
- Testing the connection to the MongoDB server.
- Listing all collections in the specified database.
- Sampling documents to understand their structure and types.
- Executing read operations, like finding documents or aggregating data.
- Executing write operations, such as inserting or updating documents.
All operations are closed with client.close() to ensure connections are not left open.
Expected Data
The mongo.adapter expects the following data format:
- Connection Settings: Must include all necessary information such as username, password, host, port, and database name.
- Query Objects for Operations:
- For read operations, queries should specify operation type (e.g.,
find,aggregate), the collection, and filters. - For write operations, queries need to specify the operation type, collection, and relevant parameters like documents or filters for updates.
- For read operations, queries should specify operation type (e.g.,
Use Cases & Examples
Use Case 1: Data Retrieval for Reporting
A business analytics team requires a reliable method to query customer data from their MongoDB database for weekly reporting. The mongo.adapter can be configured to run pre-defined queries that retrieve customer metrics.
Use Case 2: Data Integration with ETL Processes
A data engineering team wants to integrate data from various sources into their MongoDB database. They can utilize the mongo.adapter to execute write operations in bulk, simplifying the ETL workflow.
Detailed Example Configuration
For the first use case, a typical configuration to retrieve customer metrics might look like:
{
"username": "admin",
"password": "securepassword123",
"host": "db.company.com",
"port": 27017,
"databaseName": "salesDB",
"ssl": true
}Sample Query to Execute a Read Operation:
{
"operation": "find",
"collection": "customers",
"filter": {"status": "active"},
"sort": {"createdAt": -1},
"limit": 10
}This configuration connects to the salesDB database on db.company.com and retrieves the ten most recently created active customer documents from the customers collection.
Billing Impacts
Using the mongo.adapter may impact billing based on the usage of the underlying MongoDB service. Customers should monitor the number of read and write operations performed, as these may incur costs depending on the MongoDB deployment model (e.g., cloud-hosted MongoDB Atlas vs. on-premises MongoDB). Additionally, long-running queries and large result sets may influence performance and billing depending on the plan utilized for MongoDB.
Ensure to refer to specific MongoDB pricing details for a comprehensive understanding of potential costs associated with operations performed through the mongo.adapter.