MongoDB Atlas
MongoDB Atlas is a fully-managed cloud database service built on MongoDB. It provides automated backups, monitoring, and scaling capabilities across major cloud providers.
Bruin supports MongoDB Atlas as a data platform for both ingestion sources and destinations.
NOTE
MongoDB Atlas is supported as both a source and destination for ingestion using Ingestr Assets. It cannot be used for SQL-based transformations or other asset types, but you can run ad-hoc queries against it with bruin query and verify it with bruin connections test.
Connection
To set up a MongoDB Atlas connection, you need to add a configuration item to connections in the .bruin.yml file complying with the following schema.
connections:
mongo_atlas:
- name: "connection_name"
username: "your-username"
password: "your-password"
host: "cluster0.example.mongodb.net"Parameters:
name: The name to identify this MongoDB Atlas connection in Bruin assets and pipeline defaultsusername: MongoDB Atlas database usernamepassword: MongoDB Atlas database passwordhost: MongoDB Atlas cluster hostname, without themongodb+srv://protocol (e.g.,cluster0.example.mongodb.net)database: Optional. If set, Bruin appends it to the connection URI path. For ingestr assets, the target database is usually provided insource_tableordestination_tableasdatabase.collection.
NOTE
The connection uses the mongodb+srv:// protocol, which is the standard for MongoDB Atlas connections. You don't need to specify the protocol or a port in the configuration.
Bruin turns this configuration into a MongoDB Atlas URI in the following form:
mongodb+srv://your-username:your-password@cluster0.example.mongodb.netIf your username or password contains special characters, Bruin URL-encodes them when it builds the URI.
Querying
You can run ad-hoc queries against a MongoDB Atlas connection with the query command. Because MongoDB is not SQL, the query is a JSON object describing a find or aggregation against one collection:
bruin query --connection connection_name \
--query '{"collection":"users","filter":{"age":{"$gt":21}},"sort":{"age":-1},"limit":10}'See Querying MongoDB for the full envelope syntax.
Using MongoDB Atlas as a Destination
MongoDB Atlas can be used as a destination for Ingestr Assets. This allows you to load data from various sources into your MongoDB Atlas cluster.
Example: Load data from PostgreSQL to MongoDB Atlas
name: ingest.users
type: ingestr
connection: postgres
parameters:
source_connection: postgres
source_table: 'public.users'
destination: mongo_atlas
destination_connection: connection_name
destination_table: 'mydb.users'This configuration will:
- Extract data from the
public.userstable in PostgreSQL - Load the data into the
userscollection in themydbMongoDB Atlas database
destination_connection must match the name of a mongo_atlas connection in .bruin.yml. destination_table uses database.collection format.
Using MongoDB Atlas as a Source
MongoDB Atlas can also be used as a source for Ingestr Assets. This allows you to ingest data from your MongoDB Atlas cluster into various destinations such as data warehouses.
Example: Load data from MongoDB Atlas to PostgreSQL
name: public.atlas_users
type: ingestr
connection: postgres
parameters:
source_connection: connection_name
source_table: 'users.details'
destination: postgresThis configuration will:
- Extract data from the
detailscollection in theusersMongoDB Atlas database - Load the data into the
public.atlas_userstable in PostgreSQL
source_connection must match the name of a mongo_atlas connection in .bruin.yml. source_table uses database.collection format.