MongoDB Driver Documentation
This documentation explains the MongoDB driver implementation and how connection parameters map to UI fields in the Gigantic application.
Connection Parameters
| UI Field | Technical Implementation | Description | Required | Default Value |
|---|---|---|---|---|
| Host | host in mongodb connection config | The hostname or IP address of the MongoDB server | Yes | localhost |
| Port | port in mongodb connection config | The port number MongoDB server is listening on | Yes | 27017 (from driverPorts) |
| Database | db in mongodb connection config | The name of the database to connect to | Yes | None (must be specified) |
| Username | user in mongodb connection config | Database user for authentication | No | None |
| Password | password in mongodb connection config | Password for the database user | No | None |
Technical Details
The MongoDB driver implementation uses the mongodb Node.js library with MongoClient for connections.
- Document-based database using collections instead of tables
- Connection string format:
mongodb://host:portor custom URL viaconfig.url - Schema extraction performed by sampling documents from collections
- Foreign key relationships detected by looking up ObjectId references across collections
- Uses document sampling approach for schema inference
- Supports connection options like
useUnifiedTopology: true
When SSH tunneling is enabled, connections are first established through the tunnel before connecting to the MongoDB server.
Authentication Options
MongoDB supports standard username/password authentication and also connection string based authentication.
| Auth Type | UI Mapping | Description |
|---|---|---|
| None | No username/password fields | Connects without authentication |
| Password | Username/Password fields | Standard username/password authentication |
| Password Manager | Various password manager fields | Fetches credentials from external password managers |
SSH Tunnel Support
The MongoDB driver supports SSH tunneling for secure access to databases behind firewalls or in private networks. For detailed information on configuring SSH tunnels, please refer to the SSH Tunnelling documentation.
API Endpoints Used
MongoDB connections are primarily used in:
- Tap creation (data source discovery)
- Sink creation (data destination for anonymized data)
- Pipeline execution (data extraction and loading)
Large Tables and Resume
This section lists only what is specific to MongoDB. How resume, parallel ranges and row estimates work in every driver is explained in Large databases.
Reading
- Collections are read in chunks ordered by
_id, so a job that stops resumes after the last_idit saved. Each chunk is an aggregation run withallowDiskUse. - A collection whose
_idvalues are of several BSON types (for example ObjectIds and strings) is read with one cursor and starts over if the job stops. The job log says ithas _ids of several types. - A where whose first stage is a pipeline stage other than
$matchalso reads the collection with one cursor, because that stage may change the documents or their_id.
Parallel Ranges and Row Estimates
- Ranges are cut from a
$sampleof the_idvalues. Collections with_idvalues of several types are not split. - The row estimate is
estimatedDocumentCount(), read from the collection metadata.
Loading
- Documents are written with ordered
insertMany. The truncate option removes the documents withdeleteMany; the drop option drops the collection. - To resume a collection, the sink counts its documents with
countDocuments. The MongoDB sink does not count the documents of one key range, so when a collection was read in ranges and the count does not tell which batches in flight were written, the collection starts over.
Custom Params
The MongoDB driver supports additional custom parameters that can be specified in YAML format to fine-tune connection behavior, pooling, SSL settings, and other advanced options.
Connection Parameters
# SSL/TLS Configuration
tls: true
tlsCAFile: /path/to/ca.pem
tlsCertificateKeyFile: /path/to/client-cert.pem
tlsCertificateKeyFilePassword: certificate_password
tlsAllowInvalidCertificates: false
tlsAllowInvalidHostnames: false
tlsInsecure: false
# Authentication Options
authMechanism: "SCRAM-SHA-256" # or "SCRAM-SHA-1", "MONGODB-X509", "GSSAPI", "PLAIN"
authSource: "admin"
authMechanismProperties:
SERVICE_NAME: "mongodb"
CANONICALIZE_HOST_NAME: false
# Timeout Settings
connectTimeoutMS: 30000
socketTimeoutMS: 360000
serverSelectionTimeoutMS: 30000
heartbeatFrequencyMS: 10000
maxIdleTimeMS: 30000
# Read Preferences
readPreference: "primary" # or "primaryPreferred", "secondary", "secondaryPreferred", "nearest"
maxStalenessSeconds: 90
# Compression
compressors: ["snappy", "zlib"]
zlibCompressionLevel: 6Pool Configuration
# Pool sizing options
maxPoolSize: 100
minPoolSize: 10
maxConnecting: 2
# Pool timeout options
maxIdleTimeMS: 30000
waitQueueTimeoutMS: 0Example Configurations
Basic Configuration
maxPoolSize: 50
serverSelectionTimeoutMS: 5000SSL Configuration
tls: true
tlsCAFile: ${file:/path/to/ca-cert.pem}
tlsCertificateKeyFile: ${file:/path/to/client-cert.pem}
tlsCertificateKeyFilePassword: cert_password
authMechanism: "MONGODB-X509"Replica Set Configuration
host: rs1.example.com,rs2.example.com,rs3.example.com
port: 27017
database: replicated_db
readPreference: "secondaryPreferred"
maxStalenessSeconds: 120
maxPoolSize: 25
minPoolSize: 5
compressors: ["snappy"]