Skip to main content

MongoDB

info

For MongoDB ingestion, distinguish the authentication database from the database containing business collections. Use the corresponding placeholders for BSON Date and Timestamp. For device grouping, ${device} expands to a complete JSON condition; do not add quotation marks.

Entry point: taosExplorer → Data In → MongoDB.

MongoDB reads collections using JSON query templates, not relational SQL templates. The actual reading host is taosX or the selected taosX-Agent host and needs read permissions on the source database and collections.

1. Prepare Data and Identity​

Obtain the host, port, user, password, and authentication database. The authentication database is where authentication occurs, not necessarily where business collections are stored. Prepare a small collection, record whether its business-time field is BSON Date or BSON Timestamp, and retain a few known records.

PrerequisiteHow to confirm
Reading hostCheck the source port from the actual taosX or taosX-Agent host; 27017 is common. The service identity must access required certificate files.
Authentication and source permissionsThe source administrator supplies the authentication database, identity, and read permissions on business databases/collections. Successful authentication does not imply collection read access.
TLSPrepare a CA and client certificate/key material according to policy. When TLS is enabled, upload them using the page fields. Do not disable TLS to bypass certificate problems.
Source dataConfirm time field types, device identifiers, nested paths, committed windows, and representative documents. Start with a fixed database and collection.
TargetPrepare a separate test database and writable identity. Check target types, time precision, and device child tables against samples.

An authorized TDengine TSDB administrator creates a separate target database in taosExplorer's Data Browser or the taos CLI, for example CREATE DATABASE mongodb_demo PRECISION 'ms';. Determine the target supertable, child tables, and time/value types from samples first. Do not treat nested objects directly as regular numeric columns.

1.1 Configure Connection and Authentication​

Under Data In, click Create New Task, select MongoDB, and enter the task name, target database, and agent. Enter the actual source Server Address and Server Port. Gray 127.0.0.1 and 27017 are format hints, not evidence that remote MongoDB is deployed on the collection host.

MongoDB server address and port

Under Authentication, enter the source user, password, and authentication database. Obtain the authentication database from the source administrator. Do not change an existing user's authentication location simply because admin is common. To distinguish connections at the source, enter Application Name under Connection Options. It does not affect target database or table names.

MongoDB user, password, and authentication database

MongoDB application name configuration

1.2 TLS Material and Entry Point Checks​

For encrypted connections, prepare both a CA file and a certificate file containing the client certificate and private key. Both must be accessible to the service identity on the actual reading host. If the UI provides upload controls, expand SSL Certificates, upload both, and check connectivity. Do not upload only a public certificate without the required private key, or set only tls=true while omitting both file paths.

Some deployments may show only explanatory text in this panel, without upload controls. Record the taosExplorer and taosX versions and panel state, then ask the administrator or technical support to confirm the matching entry point. Do not repeatedly expand the panel or disable source TLS to bypass it. Command-line connection parameters are ca_file_path and cert_key_file_path, with paths on the execution host. Before switching to the command line, still configure complete queries and mappings. Certificate paths alone cannot start a production migration.

warning

Enabling TLS in the MongoDB connector does not imply strict certificate validity and server host name verification. In environments requiring strict identity checking, have the security administrator confirm that the connection method meets requirements first. Uploading a CA or passing a connectivity check does not prove identity verification succeeded.

2. Configure and Start​

  1. Add a MongoDB data source, select the target database and agent, and configure connection, identity, and authentication database. Upload SSL files as required by the server and check connectivity.
  2. Select the actual database and collection. Use fixed names initially, not dynamically date-expanded names.
  3. For BSON Date field event_time, enter the following query template. Set a one-minute start/end window known to contain data and specify the time zone.
{"event_time":{"$gte":${start_datetime},"$lt":${end_datetime}}}
note

This is a task template, not directly executable strict JSON before substitution. For BSON Timestamp fields, use ${start_timestamp}/${end_timestamp}. Do not change only the field name while retaining incorrect date placeholders.

  1. Enter {"event_time":1} as query sorting. Leave subtable fields unset initially, then retrieve samples and configure mapping using the process below.
  2. Preview target tables and types, record actual names, submit, and return to the task list to confirm status. If the task is not running, start the original task, then verify data.

The following configuration example uses source database source_demo, collection readings, and empty subtable fields. Its query template and sorting use the event_time condition above. The page time zone is Asia/Shanghai, the start/end range is 2026-11-20 08:00:00 to 08:01:00, the query interval is 1 hour, and delay is 0 seconds. This version offers query intervals only in days and hours; the explicit end time limits this read to one minute. Replace these with source-confirmed objects and windows. Filled-in fields in the image do not demonstrate a source query or completed ingestion.

MongoDB fixed database and collection, event_time condition, and bounded one-minute configuration

2.1 Complete Mapping from Samples​

  1. Under Payload Transformation, click Retrieve from Server and confirm the samples belong to the selected database, collection, and test window. The initial sample row count is 5, with a maximum of 100; it is not the task's total read count.
  2. Under Parsing, select json and preview business time, devices, and values. Top-level BSON Date appears as a time string in samples. Do not use the query template's $date wrapper directly as a Payload path.
  3. If nested fields need separate extraction, configure actual paths under Extract or Split from Columns and preview them. Do not copy another source's vValue splitting. If fields are absent, correct samples and extraction paths first.
  4. Add filters only when required by the business. For example, to exclude negative values, confirm the actual numeric column name, then preview positive, negative, and null samples separately. Do not bypass quality requirements merely to obtain data.
  5. Select or create a target supertable. Map business time to the time primary key, numeric values to value columns, and device identifiers to child table names and tags. Preview expanded databases/tables, types, and typical values before submitting.

MongoDB sample retrieval, parsing, extraction, filtering, and target mapping

If preview fails, check JSON parsing and source fields first. Do not mask field-path errors with automatic addition of missing columns. For shared expressions and mapping rules, see Data Processing and Modeling.

View nested-document mapping results

The separate example below includes source fields such as _id, name, createtime, versions, objectvalue, and nestedArray on the left, with a target preview on the right. Arrays and nested objects appear as text in the image. This does not mean each element has been written as a separate target row or regular numeric column.

MongoDB document parsing, target rules, and mapping result preview

Use actual samples to decide whether to preserve entire structures, extract subfields, or expand arrays. These choices change target types and row counts. The image maps createtime to the time column, while this page's query example filters by event_time. The actual mapping must use the agreed business time; do not substitute fields merely because their names are similar. Child table expressions and the test supertable in the image are illustrative. Use this task's model preview and target queries as the basis.

3. Key Configuration​

FieldUsage
Authentication databaseUse the authentication location provided by the source administrator. Do not assume every user is in admin because it is common.
Application nameDistinguishes task connections at the source; does not determine target table names.
Database and collectionBusiness objects, which can use date variables. Keep these separate from the authentication database.
Query template and sortingThe template is a MongoDB condition document. Sorting can be {"event_time":1,"device":1}; 1 is ascending and -1 is descending.
Start/end timesStart is required. Set an explicit end for bounded migrations; no end means continuous reads. Confirm times in the selected page time zone.
Query interval and delayInitial UI values are 1 day and 0 seconds. Explicitly set a small window and set delay according to commit and late-arrival ranges.

Start and end times are absolute instants with UTC offsets, unaffected by the task time zone. Task parameter time_zone has no separate taosExplorer field. If unset, it uses the start time's UTC offset: the page offset when the start was set. Editing without changing the start preserves both time bounds and the task time zone. Only fixed offsets such as +08:00 or +0800, or UTC or Z, are accepted, not IANA names such as Asia/Shanghai. Invalid values fail at task start or preview. The offset is fixed and does not follow daylight saving time. To use UTC, switch the page time zone before setting the start, or set time_zone=UTC through the API or CLI.

The task time zone determines database/collection date variables and window boundaries. Each window is at most one Query Interval long and never crosses midnight in the task time zone; intervals over 1 day behave as 1 day. Query Interval does not schedule queries. With no end or a future end, taosX first reads history to the safe watermark, current time minus delay, then checks about once per second. It reads when the range from the checkpoint to that watermark exceeds 10 seconds, splitting it by Query Interval. With a 60-second delay, a query run at 09:01 reads only data before 09:00; this does not imply hourly queries. Delay cannot reread historical updates already passed.

Pair subtable fields with corresponding template filter conditions. MongoDB conditions are JSON field expressions, not SQL.

The table's 0 seconds is the initial UI value. A direct source DSN without delay defaults to 5 seconds. Explicitly check delay and time ranges when switching entry points. For named parameters, TLS path conditions, duration units, and query template definitions, see MongoDB Read Parameters. Do not apply arbitrary native MongoDB client URI parameters to this connector.

3.1 Read Devices Separately​

For example, enter device in Subtable Fields and use this query template:

{"event_time":{"$gte":${start_datetime},"$lt":${end_datetime}},${device}}

${device} expands to a complete JSON field condition, such as "device":"d001", not just a device value. Separate multiple fields with commas and no spaces, such as device,line, and reference both ${device} and ${line} in the template. Also map grouping fields to target child table names or tags; query conditions alone are insufficient.

For field names containing }, use an explicit reference such as $field{"region}code"}. The quoted name follows JSON string escaping rules. Place the placeholder at a JSON object member position. A complete condition object can be {${site}} or {$field{"site"}}; neither {"site":${site}} nor {"site":{"$in":[${site}]}} is valid, including in earlier versions.

During upgrade validation, preview existing tasks using Retrieve from Server. Legacy placeholders in object member positions need no change when there is no local ambiguity. If a position can match multiple configured fields, such as region and region}, the template fails even when only one expansion makes the whole query valid JSON. Replace the reported placeholder with $field{"region"} or $field{"region}"}, then preview again.

null and undefined do not participate in grouping. taosX collects each subtable field's distinct values from all documents in every collection involved in the import. If any configured field has no usable value after combining collections, taosX logs a warning naming the field and skips that import.

Date placeholders represent window bounds as BSON Date milliseconds. For Timestamp placeholders, t is the bound's Unix seconds and i is always 0. Both denote absolute instants independent of the task time zone; do not add quotes. For the window from 2024-06-01T00:00:00Z to 2024-06-02T00:00:00Z, the expanded values are:

PlaceholderExpanded value (Extended JSON)
${start_datetime}{"$date":{"$numberLong":"1717200000000"}}
${end_datetime}{"$date":{"$numberLong":"1717286400000"}}
${start_timestamp}{"$timestamp":{"t":1717200000,"i":0}}
${end_timestamp}{"$timestamp":{"t":1717286400,"i":0}}

Do not treat Timestamp seconds as a millisecond Date or manually supply the internal increment as a substitute for business time.

3.2 Switch Source Databases and Collections by Date​

These variables expand using the current read window's start and task time zone. They are not for target child table naming. The examples below use 2024-01-02:

VariableMeaningExample
${Y} / ${y}Full year/remainder after dividing the year by 100, zero-padded to four/two digits2024 / 24
${M} / ${m}Month without/with zero padding1 / 01
${B} / ${b}Full/abbreviated English month nameJanuary / Jan
${D} / ${d}Day without/with zero padding2 / 02
${J} / ${j}Day of year without padding/with three digits2 / 002
${F}Hyphenated year-month-day2024-01-02
${Ymd} / ${ymd}Four-/two-digit year followed by month and day20240102 / 240102
${md} / ${dm}Month-day/day-month0102 / 0201
${Yj} / ${yj}Year followed by three-digit day of year2024002 / 24002

Dynamic database/collection placeholders suit existing partition-named systems, but verify day boundaries, month boundaries, and missing collections first. Do not cover all historical collections in the first test.

For example, database_${Y} and collection_${md} resolve to database_2024.collection_0102 in that window. This does not automatically discover older collections with nonmatching names or create source collections. Confirm windows, the actual object inventory, and missing-object handling in advance.

4. Advanced Options and Write Error Policies​

Expand Advanced Options, distinguish read concurrency, batches, and query windows, then check Error Handling Policy. Nested-document parsing or array expansion can change the number of target rows per document. Before selecting archiving, discarding, or automatic column expansion, preview normal samples, missing fields, and type changes separately. Target connection caching cannot recover changes to old documents that were never queried.

MongoDB read concurrency, batch, and health settings

This form initially sets read concurrency to 0 and batch size to 10000. Neither changes query window boundaries, and the batch is not a MongoDB cursor network batch. For direct DSN defaults, zero values, and scope, see Advanced Query Source Parameters. Verify a small window first, then measure source queries and target writes separately using Tuning and Resource Control.

For archive retrieval and assessing affected scope, see Write Errors and Invalid Data.

5. Verification​

Check source records in the MongoDB client using the same collection, time type, and window, then query actual child tables in taosExplorer's Data Browser or the taos CLI. Compare times, devices, numeric values, nulls, and nested-field extraction results. Source document counts can differ from mapped target row counts because of expansion, filtering, or same-primary-key overwrites. Start with a few identifiable documents.

6. Troubleshooting, Recovery, and Limitations​

SymptomChecks
Authentication failsCheck the authentication database, user, and read permissions on the actual business database.
Empty queries or type errorsCheck BSON Date/Timestamp, placeholders, and whether source fields are missing.
Missing preview fieldsCheck structural differences among documents, nested paths, and sample representativeness.

Stop and resume the original task, retaining state, and recheck the interrupted window. This template-based reading is not general Change Stream replication of all MongoDB changes. It does not guarantee replication of historical changes, deletions, or all source BSON types.

For other task, write, and runtime issues, see Troubleshooting by Symptom.