Connector Reference
MongoDB
Configure the mongodb connector to query, aggregate, and write MongoDB collections with Extended JSON ObjectId and date coercion.
MongoDB
The mongodb connector queries, aggregates, and writes documents in a MongoDB database.
When to use it
Use mongodb as a document-store source or destination, or as a lookup and staging store when your data is already in MongoDB. Filters and aggregation pipelines use native MongoDB query syntax.
Configuration
| Key | Type | Required | Default | Description |
|---|---|---|---|---|
connection_string |
string | Yes | — | MongoDB connection string (stored as a secret) |
database |
string | Yes | — | Database name |
Methods
| Method | Arguments | Returns | Behavior |
|---|---|---|---|
find |
collection (required), filter, projection, sort, limit, skip |
array | Streams documents from the driver cursor one at a time |
find_one |
collection (required), filter, projection |
object | Returns a single document |
count |
collection (required), filter |
object | Returns { count } of matching documents |
insert_one |
collection (required), data (required) |
object | Inserts a single document |
update_one |
collection (required), filter (required), update (required), upsert |
object | Updates one document; upsert: true inserts when nothing matches |
update_many |
collection (required), filter (required), update (required), upsert |
object | Updates all matching documents |
delete_one |
collection (required), filter (required) |
object | Deletes one document |
delete_many |
collection (required), filter (required) |
object | Deletes all matching documents |
aggregate |
collection (required), pipeline (required) |
array | Streams aggregation results from the driver cursor |
list_collections |
— | array | Returns { name, type } for every collection and view in the database |
Example
name: export_open_tickets
connectors:
source:
type: mongodb
steps:
- name: read_tickets
type: call_method
config: |
{
"connector": "source",
"method": "find",
"args": {
"collection": "tickets",
"filter": { "status": "open" },
"sort": { "created_at": -1 }
}
}The matching connectors.yaml entry for CLI runs:
source:
type: mongodb
config:
connection_string: ${MONGODB_CONNECTION_STRING}
database: helpdeskBehavior notes
- Filters, update documents, and pipelines are coerced from Extended JSON before execution:
{ "$oid": "..." }values becomeObjectIdinstances (invalid hex fails withInvalid ObjectId hex), and$datevalues becomeDateobjects. This lets YAML/JSON task configs express BSON types. findandaggregatereturn async iterators over the driver cursor, so large result sets stream with backpressure instead of buffering.update_oneandupdate_manytake a MongoDB update document (for example{ "$set": { ... } }) inupdate.
Related
- Connectors overview — all compiled connector types
- Data Explorer — interactively query a MongoDB Connector
- Reading and writing data — calling connector methods from steps