Read a bounded set from MongoDB¶
First run the complete local test, which requires Docker, Go, and available ports:
make test-mongodb-e2e-local
It starts a ReplicaSet and MatrixOne, then checks the connection, explicit field mapping, batch reads, filters, and failure recovery. Results are in test/mongodb/reports/. For your own MongoDB, first configure a CN endpoint allowlist and account-scoped secret://env/ credentials as described in CREATE MONGODB CONNECTION. Then, as an account administrator, run:
CREATE MONGODB CONNECTION docs_mongo WITH (
'hosts' = 'mongo.example.com:27017',
'credential_secret_ref' = 'secret://env/MO_MONGODB_DOCS_CREDENTIAL',
'replica_set' = 'rs0'
);
CREATE DATABASE cookbook_mongo;
CREATE EXTERNAL TABLE cookbook_mongo.events (
event_id VARCHAR(64) MONGODB_PATH '_id',
device_id VARCHAR(64),
ts DATETIME MONGODB_CONVERT 'try_null'
) ENGINE = MONGODB WITH (
'connection' = 'docs_mongo', 'database' = 'app',
'collection' = 'events', 'schema_mode' = 'explicit'
);
SELECT event_id, device_id, ts FROM cookbook_mongo.events
WHERE ts >= '2026-01-01' AND ts < '2026-02-01' ORDER BY ts LIMIT 10;
Compare IDs with MongoDB documents in the same time range. If the query is empty, first check that the source collection contains matching documents. Remove the mapping before the connection: DROP DATABASE cookbook_mongo; DROP MONGODB CONNECTION docs_mongo;. Without the allowlist or credential, access is denied by design.