The MongoDB data source connector allows you to fetch data from the NoSQL MongoDB database. Supported MongoDB versions are from 4.4 to latest (6.0). 4.2 could work also, but not guaranteed. Lower version are not supported by version of mongoexport. Complete the following steps to configure it.
Create a new configuration and click Set Up Database Credentials and fill in the form. Then test the new credentials and save them. Optionally, set up an SSH tunnel.
Click the New Export button and configure your first export using the following options:
Name – Identifies your export; its value has to be unique across all exports and exported tables in your configuration. Also, the main exported table will be named after the value of the Name field.
Collection – Represents the collection name in your MongoDB database.
Query (optional) – JSON string specifying a query which limits documents data in exported data. Must be specified in a strict format.
Sort (optional) – JSON string specifying the order of documents in exported data. Must be specified in a strict format.
Limit (optional) – Limits the number of exported documents.
Incremental – Loads data to your tables incrementally.
Mode – Specifies the export mode: Mapping or Raw. Start by exporting few documents using the Raw mode first – it will help you see the document structure for which you need to write mapping.
Mapping – This is the most important section in case you have selected the Mapping mode; it defines how documents in the collection are mapped to the output tables. It, too, has to be valid JSON.
Tip: Use a combination of a limit (for example, only 10 documents) and a query (for example, only a document with specific ID) while playing with the mapping section to prevent a full collection export.
A strict format means standard valid JSON must be used, and you cannot use MongoDB objects as in the JavaScript shell interface. Thus using objects such as ObjectId, Date or NumberLong is not allowed until you specify them in the strict format. Read more on the strict format.
By defining mapping, you specify the structure and content of your output tables, their columns and relations between them.
Tip: Export few documents using the Raw Export Mode first – it will help you see the document structure (in Strict Format) for which you need to write mapping.
Since MongoDB identifies each document in a collection uniquely by _id
, we recommend to set
a primary key to this field by defining the first item in a mapping section:
Note: The destination column with the primary key should be named id
not _id
to prevent problems with
the data import.
To handle MongoDB data types correctly, define mapping similarly to the following example for
MongoId
, ISODate
, and NumberLong
data types.
Document | |
Document in Strict Mode | |
Mapping |
Check out more mapping examples.
In the raw export mode, documents are exported as plain JSON strings.
Document | |||||
Document in Strict Mode | |||||
Output |
|