MongoDB

Find, insert, update, and delete documents in MongoDB collections.

Data and storageAPI key7 actionsAll integrations

On this page
  1. Connect
  2. Call it from a workflow
  3. Actions (7)
  4. find_documents
  5. update_documents
  6. aggregate_documents
  7. delete_documents
  8. find_and_replace_documents
  9. find_and_update_documents
  10. insert_documents
  11. Details

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.

Workflow
// 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);
});
Try it from your agent
{
  "name": "integrations",
  "arguments": {
    "project_id": "<project-id>",
    "action": "call",
    "piece": "mongodb",
    "piece_action": "find_documents",
    "input": {
      "collection": "<collection>"
    },
    "env": "dev"
  }
}
From another backend (connector proxy)
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

InputTypeDescription
databaseoptionaltextThe MongoDB database to connect to (from your authentication)
collectionrequiredid (picked from your account)Collection
queryoptionalJSONMongoDB query to filter documents (e.g., {"status": "active"})
projectionoptionalJSONFields to include or exclude (e.g., {"name": 1, "_id": 0})
sortoptionalJSONSort criteria (e.g., {"createdAt": -1})
limitoptionalnumberMaximum number of documents to return
skipoptionalnumberNumber of documents to skip

update_documents

Update Documents. Update multiple documents in a collection

InputTypeDescription
databaseoptionaltextThe MongoDB database to connect to (from your authentication)
collectionrequiredid (picked from your account)Collection
filterrequiredJSONMongoDB query to select documents to update (e.g., {"status": "pending"})
updaterequiredJSONMongoDB update operations (e.g., {"$set": {"status": "completed"}})
upsertoptionalbooleanInsert a document if no documents match the filter

aggregate_documents

Aggregate Documents. Perform aggregation operations on documents in a collection

InputTypeDescription
databaseoptionaltextThe MongoDB database to connect to (from your authentication)
collectionrequiredid (picked from your account)Collection
pipelinerequiredJSONArray of aggregation stages (e.g., [{"$match": {"status": "active"}}, {"$group": {"_id": "$category", "count": {"$sum": 1}}}])

delete_documents

Delete Documents. Delete documents from a collection

InputTypeDescription
databaseoptionaltextThe MongoDB database to connect to (from your authentication)
collectionrequiredid (picked from your account)Collection
filterrequiredJSONMongoDB 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

InputTypeDescription
databaseoptionaltextThe MongoDB database to connect to (from your authentication)
collectionrequiredid (picked from your account)Collection
filterrequiredJSONMongoDB query to select documents to replace (e.g., {"_id": "123"})
replacementrequiredJSONNew document that will replace the matched documents
upsertoptionalbooleanInsert the document if no documents match the filter
returnDocumentoptionalone 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

InputTypeDescription
databaseoptionaltextThe MongoDB database to connect to (from your authentication)
collectionrequiredid (picked from your account)Collection
filterrequiredJSONMongoDB query to select documents to update (e.g., {"status": "pending"})
updaterequiredJSONMongoDB update operations (e.g., {"$set": {"status": "completed"}})
upsertoptionalbooleanInsert a document if no documents match the filter
returnUpdatedoptionalbooleanReturn the documents after updates are applied

insert_documents

Insert Documents. Insert one or more documents into a collection

InputTypeDescription
databaseoptionaltextThe MongoDB database to connect to (from your authentication)
collectionrequiredid (picked from your account)Collection
documentsrequiredJSONDocument(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