MongoDB

MongoDB is a popular NoSQL document database.

Overview

The MongoDB connector lets your Spojit workflows read and write documents in any MongoDB deployment - Atlas, self-hosted, or a managed provider. It speaks the standard MongoDB wire protocol, so you can query, insert, update, delete, aggregate, and run admin commands across databases and collections from a single connection.

Use it as a flexible store for AI-processed data, as the destination for syncs from structured systems like MySQL or NetSuite, or as the source-of-truth for analytics pipelines. MongoDB's schemaless model makes it a natural landing zone for mixed-shape data flowing through multi-system workflows.

What You Can Do

The MongoDB connector exposes these tools:

  • find-documents - Query a collection with a filter, projection, sort, and limit.
  • insert-documents - Insert one or many documents into a collection.
  • update-documents - Update documents matching a filter (supports upsert).
  • delete-documents - Delete documents matching a filter.
  • count-documents - Count documents matching a filter without returning them.
  • aggregate - Run an aggregation pipeline ($match, $group, $lookup, etc.).
  • list-databases - List every database on the cluster.
  • list-collections - List collections in a database.
  • run-command - Run any MongoDB command for operations not covered by the dedicated tools.

Authentication

The connector authenticates with a MongoDB connection string. For Atlas, open the cluster and click Connect -> Drivers to copy a SRV connection string in the form mongodb+srv://<user>:<password>@cluster.mongodb.net/. For self-hosted deployments, use a standard mongodb://host:port URI with credentials encoded inline or supplied separately.

Create a dedicated database user with the least privileges your workflows need: readWrite on a specific database is usually enough. In Atlas, allowlist the Spojit egress IPs (or temporarily allow 0.0.0.0/0 during setup) under Network Access, otherwise the connection will hang on the first call.

Setting Up Your Connection

  1. In MongoDB Atlas, create a database user under Database Access and add the Spojit IPs under Network Access.
  2. Copy the connection string from Connect -> Drivers and substitute the user password.
  3. In Spojit, go to Connections and click + Add Connection.
  4. Search for MongoDB and select it.
  5. Paste the connection string and optionally set a default database.
  6. Name the connection (e.g. MongoDB - Analytics Cluster) and click Save. Spojit calls list-databases to verify the credentials.

Using in a Workflow

Add a Connector node, select your MongoDB connection, and pick a mode:

  • Direct Mode - You name the tool and pass the filter, document, or pipeline. Use this for high-volume reads and writes where you know exactly which collection to hit.
  • Agent Mode - The AI agent picks tools and shapes filters from a prose goal. Use this for ad-hoc analytics queries or when an agent needs to explore the data.

Prefer aggregate over multiple find-documents + transform steps when you can express the work as a pipeline - it runs server-side and avoids round-trips.

Tips

  • Index the fields you filter on. A missing index turns a quick find-documents into a full collection scan that times out on large collections.
  • Use upserts for sync workflows. Set upsert: true on update-documents so a single tool call either inserts or updates - cleaner than a find-then-write pattern.
  • Batch inserts. insert-documents accepts an array; one call with 1000 documents is much faster than 1000 calls with one document each.
  • Use projections. When workflows only need a few fields, project them in find-documents to cut payload size and downstream token usage in AI steps.

Common Pitfalls

  • IP allowlist blocks the first call. If the connection hangs and never returns, check Atlas Network Access - this is the most common setup issue.
  • ObjectId vs string. The _id field is an ObjectId, not a string. Filters that pass a string _id match nothing. Cast with { "$oid": "..." } in extended JSON or use the helper in aggregate.
  • Aggregation pipeline limits. Pipelines have a 100MB memory limit per stage unless you set allowDiskUse: true. Long sort or group stages will fail otherwise.
  • No transactions across collections by default. Multi-document updates aren't atomic unless you run them in an explicit transaction via run-command.
  • Connection string secrets. The password sits inside the URI. Rotate it the moment a user with connection access leaves the workspace.

Common Use Cases

Related Articles

For technical API details and field specifications, see the MongoDB connector documentation.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.