MongoDB Query
The MongoDB Query component uses the MongoDB REST API to retrieve data and load it into a table. This stages the data, so the table is reloaded each time. You can then use transformation components to enrich and manage the data in permanent tables.
When connecting to a MongoDB instance with security enabled, users must specify the AuthDatabase parameter in the Connection Options. When connecting to a replica set, users should familiarize themselves with the ReadPreference connection option.
Warning
This component is potentially destructive. If the target table undergoes a change in structure, it will be recreated. Otherwise, the target table is truncated. Setting the load option Recreate Target Table to Off will prevent both recreation and truncation. Do not modify the target table structure manually.
Properties
Name
= string
A human-readable name for the component.
Basic/Advanced Mode
= drop-down
- Basic: This mode will build a query for you using settings from the Data Source, Data Selection, and Data Source Filter parameters. In most cases, this mode will be sufficient.
- Advanced: This mode will require you to write an SQL-like query to call data from MongoDB. The available fields and their descriptions are documented in the data model.
There are some special pseudo columns that can form part of a query filter, but are not returned as data. This is fully described in the data model.
Note
While the query is exposed in an SQL-like language, the exact semantics can be surprising, for example, filtering on a column can return more data than not filtering on it. This is an impossible scenario with regular SQL.
Port
= integer
Specify a MongoDB connection port number. The default, 27017, is used if this is left blank.
Username
= string
A valid MongoDB username.
Password
= drop-down
The secret definition storing the password for your username for your MongoDB account. Your password should be saved as a secret definition before using this component.
Server
= string
The server IP or DNS address of the MongoDB server endpoint For example, {cluster-name}.cluster-xxxxxxxxxxxx.{region}.docdb.amazonaws.com
.
Database
= string
The name of the MongoDB server's database.
Flatten Objects
= boolean
- Yes: Nested document structures are flattened into a set of fields. Determining which fields are available can become expensive in this mode, since more data needs to be scanned to determine which fields are available.
- No: Nested document structures are returned as JSON strings. They can be further queried/manipulated by JSON functions in a transformation pipeline after being staged.
Flatten Arrays
= integer
Set the maximum number of elements that any array can be flattened to. Flattened arrays have each element placed into its own respective (newly created) column.
- Entering 0 for this property will ensure all arrays remain in JSON string format.
- Entering -1 for this property will ensure all elements from arrays are flattened.
- Requesting to flatten more elements than exist in an array will result in all elements of that array being flattened.
- Determining which fields are available can become expensive in this mode, since more data needs to be scanned to determine which fields are available.
Connection Options
= column editor
- Parameter: A JDBC parameter supported by the database driver. The available parameters are explained in the data model. Manual setup is not usually required, since sensible defaults are assumed.
- Value: A value for the given Parameter.
SQL Query
= code editor
Input an SQL-like query, written according to the data model.
This property is only available when Basic/Advanced Mode is set to Advanced.
Data Source
= drop-down
Select a data source.
Data Selection
= dual listbox
Choose one or more columns to return from the query. The columns available are dependent upon the data source selected. Move columns left-to-right to include in the query.
Data Source Filter
= column editor
- Input Column: Select an input column. The available input columns vary depending upon the data source.
- Qualifier:
- Is: Compares the column to the value using the comparator.
- Not: Reverses the effect of the comparison, so "Equals" becomes "Not equals", "Less than" becomes "Greater than or equal to", etc.
- Comparator: Choose a method of comparing the column to the value. Possible comparators include: "Equal to", "Greater than", "Less than", "Greater than or equal to", "Less than or equal to", "Like", "Null". "Equal to" can match exact strings and numeric values, while other comparators, such as "Greater than" and "Less than", will work only with numerics. The "Like" operator allows the wildcard character [%] to be used at the start and end of a string value to match a column. The Null operator matches only null values, ignoring whatever the value is set to. Not all data sources support all comparators, meaning that it is likely that only a subset of the above comparators will be available to choose from.
- Value: The value to be compared.
Combine Filters
= drop-down
Select whether to use the defined filters in combination with one another according to either And or Or.
Limit
= integer
Set a numeric value to limit the number of rows that are loaded.
Type
= drop-down
- External: The data will be put into your storage location and referenced by an external table.
- Standard: The data will be staged in your storage location before being loaded into a table. This is the default setting.
Primary Keys
= dual listbox
Select one or more columns to be designated as the table's primary key.
Warehouse
= drop-down
The Snowflake warehouse used to run the queries. The special value, [Environment Default], will use the warehouse defined in the environment. Read Overview of Warehouses to learn more.
Database
= drop-down
The Snowflake database. The special value, [Environment Default], will use the database defined in the environment. Read Databases, Tables and Views - Overview to learn more.
Schema
= drop-down
The Snowflake schema. The special value, [Environment Default], will use the schema defined in the environment. Read Database, Schema, and Share DDL to learn more.
Target Table
= string
The name of the table to be created.
Warning
This table will be recreated and will drop any existing table of the same name.
Stage
= drop-down
Select a managed stage. The special value, [Custom], will create a stage "on the fly" for use solely within this component.
Stage Platform
= drop-down
Select a staging setting.
- Snowflake Managed: Create and use a temporary internal stage on Snowflake for staging the data. This stage, along with the staged data, will cease to exist after loading is complete.
- Existing Amazon S3 Location: Activates the S3 Staging Area property, allowing users to specify a custom staging area on Amazon S3. The Stage Authentication property is also activated, letting users select a method of authenticating the data staging.
- Existing Azure Blob Storage Location: Activates the Storage Account and Blob Container properties, allowing users to specify a custom staging location on Azure. The Stage Authentication property is also activated, letting users select a method of authenticating the data staging.
- Existing Google Cloud Storage Location: Activates the GCS Staging Area property, allowing users to specify a custom staging area within Google Cloud Storage.
Stage Authentication
= drop-down
Select an authentication method for data staging.
- Credentials: Uses the credentials configured in the environment. If no credentials have been configured, an error will occur.
- Storage Integration: Use a Snowflake storage integration to authentication data staging. A storage integration is a Snowflake object that stores a generated identity and access management (IAM) entity for your external cloud storage, along with an optional set of allowed or blocked storage locations. To learn more, read Create Storage Integration.
Storage Integration
= drop-down
Select a Snowflake storage integration from the drop-down list. Storage integrations are required to permit Snowflake to read data from and write to your cloud storage location (Amazon S3, Azure Blob Storage, Google Cloud Storage) and must be set up in advance of selection. Only available when Stage Authentication is set to Storage Integration.
S3 Staging Area
= drop-down
Select an S3 bucket for temporary storage. Ensure your access credentials have S3 access and permission to write to the bucket. The temporary objects created in this bucket will be removed again after the load completes; they are not kept.
Use Accelerated Endpoint
= boolean
When True, data will be loaded via the s3-accelerate
endpoint. Please consider the following information:
- Enabling acceleration can enhance the speed at which data is transferred to the chosen S3 bucket. However, enhanced speed is not always guaranteed. Please consult Amazon S3 Transfer Acceleration Speed Comparison to compare S3 Direct versus S3 Accelerated Transfer speeds.
- Users must manually set the acceleration configuration of an existing bucket. To learn more, see PutBucketAccelerateConfiguration in the API Reference, available at the AWS documentation.
- This property is only available if the selected S3 bucket has Amazon S3 Transfer Acceleration enabled. For more information, including how to enable this feature, read Getting started with Amazon S3 Transfer Acceleration.
- Cases may arise where the MongoDB Query component cannot determine whether the chosen S3 bucket has Amazon S3 Transfer Acceleration enabled. In these cases, the component will reveal this property for user input on a "just in case" basis. In these cases, the component may return a validation message that reads "OK - Bucket could not be validated." You may also encounter cases where, if you do not have permission to get the status of the acceleration configuration (namely, the permission,
GetAccelerateConfiguration
), the component will again show this property "just in case". - The default setting is False.
Encryption
= drop-down
Decide how the files are encrypted inside the S3 bucket. This property is available when using an existing Amazon S3 location for staging.
- None: No encryption.
- SSE KMS: Encrypt the data according to a key stored on KMS. Read AWS Key Management Service (AWS KMS) to learn more.
- SSE S3: Encrypt the data according to a key stored on an S3 bucket. Read Using server-side encryption with Amazon S3-managed encryption keys (SSE-S3) to learn more.
KMS Key ID
= drop-down
The secret definition storing the ID of the KMS encryption key you have chosen to use in the Encryption property. Your encryption key should be saved as a secret definition before using this component.
Load Options
= multiple drop-downs
Set each of the following options:
- Clean Staged Files: Destroy staged files after loading data. Default is On.
- String Null is Null: Converts any strings equal to null into a null value. This is case-sensitive and only works with entirely lower-case strings. Default is Off.
- Recreate Target Table: Choose whether the component recreates its target table before the data load. If Off, the existing table will be used. Default is On.
- File Prefix: Give staged file names a prefix of your choice. Default is empty (no prefix).
- Trim String Columns: Remove leading and trailing characters from a string column. Default is On.
- Compression Type: Set the compression type to either gzip (default) or None.
New Table Name
= string
The name of the new table to be created. Only available when Type is set to External.
Stage Database
= drop-down
Specify the stage database. The special value, [Environment Default], will use the database defined in the environment. Only available when Type is set to External.
Stage Schema
= drop-down
Specify the stage schema. The special value, [Environment Default], will use the schema defined in the environment. Only available when Type is set to External.
Stage
= drop-down
Select a stage. Only available when Type is set to External.
Auto Debug
= drop-down
Choose whether to automatically log debug information about your load. These logs can be found in the task history and should be included in support requests concerning the component. Turning this on will override any debugging connection options.
Debug Level
= drop-down
The level of verbosity with which your debug information is logged. Levels above 1 can log huge amounts of data and result in slower execution.
- Will log the query, the number of rows returned by it, the start of execution and the time taken, and any errors.
- Will log everything included in Level 1, plus cache queries and additional information about the request, if applicable.
- Will additionally log the body of the request and the response.
- Will additionally log transport-level communication with the data source. This includes SSL negotiation.
- Will additionally log communication with the data source, as well as additional details that may be helpful in troubleshooting problems. This includes interface commands.
Strategy
- Connect to the target database and issue the query.
- Stream the results into objects in cloud storage.
- Create or truncate the target table and issue a COPY command to load the cloud storage objects into the table.
- Finally, clean up the temporary cloud storage objects.
Connecting to Mongo Atlas
It is possible to use the MongoDB Query component to connect to Mongo Atlas with minor alterations of the component's Connection Options:
- Whitelist the Matillion Data Productivity Cloud instance IP in the Atlas Cluster Security console.
- Using the Atlas Cluster Security console, grant user read privileges on the collection to be queried by the component.
- Set the Server property on the MongoDB Query component to the primary server's hostname.
- Set Connection Option UseSSL to true.
- Set Connection Option AuthDatabase to admin.
- Set Connection Option ReplicaSet to contain a comma-separated list of all the hostnames in the replica set, including their port number. For example:
matil-dsl-shard-00-00-vli5t.mongodb.net:27017, matil-dsl-shard-00-01-vli5t.mongodb.net:27017,matil-dsl-shard-00-02-vli5t.mongodb.net:27017
.
Connecting to an Amazon DocumentDB Cluster
With your cluster created, make note of the cluster details (found by clicking on the cluster name on the Clusters page).
The table below describes the mapping from the DocumentDB cluster details to the component properties:
MongoDB Query component property | Type | Amazon DocumentDB property (value) |
---|---|---|
Port | Integer | Specify a port number. The default, 27017 , is used if this is left blank. |
Username | String | Input a valid MongoDB for authentication. |
Password | String | The corresponding password. Store the password as a secret definition. |
Server | String | The server IP or DNS address of the MongoDB server endpoint. The format is: {cluster-name}.cluster-xxxxxxxxxxxx.{region}.docdb.amazonaws.com |
In addition to the above details, set the following additional connection options (in the Connection Options component property) to connect to an Amazon DocumentDB cluster:
Connection Option | Value | Description |
---|---|---|
UseSSL | True | Amazon DocumentDB Clusters have SSL enabled by default and this can't be changed. |
SSLServerCert | * | This automatically accepts the certificate presented by the DocumentDB Cluster, which is already hosted within the same region and security group as the EC2 instance. |
Other | "UseFindAPI=true" | This is set to ensure compatibility with the DocumentDB version of the MongoDB API. |