MongoDB
Find, insert, update, and delete documents in MongoDB collections.
On this page
Connect
Auth type: API key (secret_text). Pass the provider's API key or token as the connection's credential. It is sealed at rest and only opened on the server when an action runs.
- From your agent: integrations {action: "connect", piece, credentials, env} stores the credentials for dev, prod or all. Answers name the fields, never the values.
- Or set the integration's project secrets with the secrets tool (SLACK_BOT_TOKEN, DISCORD_WEBHOOK_URL, TELEGRAM_BOT_TOKEN, TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN …): a call uses the connection, else those secrets. integrations {action: "catalog", piece} lists which ones work.
- Try one action now with integrations {action: "call", piece, piece_action, input}. It really sends.
Call it from a workflow
step.ctx.integrations.invoke("mongodb", action, input) resolves with the provider's answer and rejects when MongoDB isn't connected or refuses. Wrap it in step.run so a retry sends once. See step.ctx. Its actions run through the integration runner, which the server's operator turns on: integrations {action: "catalog", piece: "mongodb"} says whether yours can call it.
// workflows/notify.ts: call MongoDB when a booking is confirmed
import { on } from "@appbricx/workflows";
export const tellMongodb = on.transition("booking", "status", "confirmed", async (_event, step) => {
// Recorded once: a retry doesn't send it twice. Rejects when MongoDB isn't connected.
const output = await step.run("MongoDB", () =>
step.ctx.integrations.invoke("mongodb", "find_documents", {
"collection": "<collection>"
}),
);
step.ctx.log("MongoDB answered", output);
});{
"name": "integrations",
"arguments": {
"project_id": "<project-id>",
"action": "call",
"piece": "mongodb",
"piece_action": "find_documents",
"input": {
"collection": "<collection>"
},
"env": "dev"
}
}curl -X POST "$APP_ORIGIN/__appbricx/connector-proxy/mongodb/find_documents" \
-H "Authorization: Bearer $APP_KEY" \
-H "content-type: application/json" \
-d '{"props":{"collection":"<collection>"}}'Actions
find_documents
Find Documents. Find documents in a collection
| Input | Type | Description |
|---|---|---|
databaseoptional | text | The MongoDB database to connect to (from your authentication) |
collectionrequired | id (picked from your account) | Collection |
queryoptional | JSON | MongoDB query to filter documents (e.g., {"status": "active"}) |
projectionoptional | JSON | Fields to include or exclude (e.g., {"name": 1, "_id": 0}) |
sortoptional | JSON | Sort criteria (e.g., {"createdAt": -1}) |
limitoptional | number | Maximum number of documents to return |
skipoptional | number | Number of documents to skip |
update_documents
Update Documents. Update multiple documents in a collection
| Input | Type | Description |
|---|---|---|
databaseoptional | text | The MongoDB database to connect to (from your authentication) |
collectionrequired | id (picked from your account) | Collection |
filterrequired | JSON | MongoDB query to select documents to update (e.g., {"status": "pending"}) |
updaterequired | JSON | MongoDB update operations (e.g., {"$set": {"status": "completed"}}) |
upsertoptional | boolean | Insert a document if no documents match the filter |
aggregate_documents
Aggregate Documents. Perform aggregation operations on documents in a collection
| Input | Type | Description |
|---|---|---|
databaseoptional | text | The MongoDB database to connect to (from your authentication) |
collectionrequired | id (picked from your account) | Collection |
pipelinerequired | JSON | Array of aggregation stages (e.g., [{"$match": {"status": "active"}}, {"$group": {"_id": "$category", "count": {"$sum": 1}}}]) |
delete_documents
Delete Documents. Delete documents from a collection
| Input | Type | Description |
|---|---|---|
databaseoptional | text | The MongoDB database to connect to (from your authentication) |
collectionrequired | id (picked from your account) | Collection |
filterrequired | JSON | MongoDB query to select documents to delete (e.g., {"status": "archived"}) |
find_and_replace_documents
Find and Replace Documents. Replace documents that match a filter with a new document
| Input | Type | Description |
|---|---|---|
databaseoptional | text | The MongoDB database to connect to (from your authentication) |
collectionrequired | id (picked from your account) | Collection |
filterrequired | JSON | MongoDB query to select documents to replace (e.g., {"_id": "123"}) |
replacementrequired | JSON | New document that will replace the matched documents |
upsertoptional | boolean | Insert the document if no documents match the filter |
returnDocumentoptional | one of "before" | "after" | Which version of the document to return |
find_and_update_documents
Find and Update Documents. Find documents and update them, returning the updated documents
| Input | Type | Description |
|---|---|---|
databaseoptional | text | The MongoDB database to connect to (from your authentication) |
collectionrequired | id (picked from your account) | Collection |
filterrequired | JSON | MongoDB query to select documents to update (e.g., {"status": "pending"}) |
updaterequired | JSON | MongoDB update operations (e.g., {"$set": {"status": "completed"}}) |
upsertoptional | boolean | Insert a document if no documents match the filter |
returnUpdatedoptional | boolean | Return the documents after updates are applied |
insert_documents
Insert Documents. Insert one or more documents into a collection
| Input | Type | Description |
|---|---|---|
databaseoptional | text | The MongoDB database to connect to (from your authentication) |
collectionrequired | id (picked from your account) | Collection |
documentsrequired | JSON | Document(s) to insert. Can be a single document object or an array of documents. |
Details
- Id
mongodb- Category
- Data and storage
- Tags
- database, nosql, document, json
- Package
@activepieces/piece-mongodb@0.1.3- Runs
- Through the integration runner