Skip to content

Document

This component connects your workflow to a MongoDB database, allowing you to manage documents stored in collections. Think of it as a tool that lets you find records, add new ones, update details, or remove items without needing to write code. It simplifies database interactions by providing a structured way to perform common actions like searching, inserting, updating, deleting, and counting documents.

How it Works

This component acts as a bridge between Nappai and your MongoDB database. You configure the connection details and specify which collection to work with. Based on the operation you select, the component performs the requested action on the database and returns the results. It handles the communication logic internally, so you can focus on defining what data you need or how you want to modify it.

Connection & Credentials

This component requires configuring a credential in the Nappai panel before interacting with the external service:

  1. Go to the Credentials section in your Nappai panel.
  2. Create a new credential of the type MongoDB Connection and fill in the required fields (API Keys, tokens, etc.).
  3. In your workflow, select the saved credential in the Credential input field of this node.

Inputs

The following fields are available to configure this component:

  • Database Name: The name of the database where your collection is stored.

  • Collection Name: The collection where you want to perform document operations.

  • Operation: Choose what you want to do: search documents, add new ones, update existing data, replace entire documents, delete, or count.

  • Filter: Specify which documents to target. Use a JSON format like {"status": "active"}. Leave empty {} to match all documents.

  • Query Filter: The query document used to select documents for Find and Count operations. Defines the criteria for retrieval.

  • Document: The data you want to add or replace. Accepts objects or JSON strings. Required for Insert and Replace operations.

  • Update Data: Specify what to change using MongoDB update operators. Use syntax like {"$set": {"status": "active"}}. Required for Update operations.

  • Upsert: Create a new document if none match your filter. Useful for updating existing data or creating it if it doesn’t exist yet.

  • Multiple Documents: Apply changes to all matching documents or just the first one found.

  • Limit: Maximum number of results to return. Set to 10 for top 10 results, or 100 for larger datasets. Default is 100.

  • Skip: Skip the first N results. Useful for pagination.

  • Sort: Order your results. Use 1 for A-Z and -1 for Z-A. Example: {"price": 1} for cheapest first.

  • Return ID: Include MongoDB’s unique _id field in the results. Keep True if you need to reference documents later.

Outputs

  • Data: Returns the processed results based on the selected operation. This can be a list of documents, a count, or a confirmation of changes, which can be used in subsequent workflow steps.

Output Data Example (JSON)json

[ { “_id”: “64f1a2b3c4d5e6f7a8b9c0d1”, “name”: “Alice Johnson”, “status”: “active”, “role”: “manager” }, { “_id”: “64f1a2b3c4d5e6f7a8b9c0d2”, “name”: “Bob Smith”, “status”: “active”, “role”: “analyst” } ]

Connectivity

This component is typically connected to a MongoDB Connection credential to access your database. The Data output can be linked to other components for further processing, such as formatting data, sending notifications, or triggering additional actions based on the retrieved or modified documents.

Usage Example

Suppose you want to find all active customers in your sales database.

  1. Set Database Name to SalesDB.
  2. Set Collection Name to Customers.
  3. Choose Operation as Find.
  4. Set Filter to {"status": "active"}.
  5. Run the workflow. The component will retrieve all active customers and output them via the Data field, which you can then use to generate a report or send welcome emails.

Tips and Best Practices

  • Always ensure you have selected the correct Database Name and Collection Name to avoid errors.
  • When using Update or Delete operations, double-check your Filter to ensure you are targeting the right documents.
  • Use the Limit input to prevent returning too many records at once, which can slow down your workflow.
  • If you need to check if a record exists before creating it, consider using the Upsert option to handle both updates and creation in one step.
  • For pagination, combine Limit and Skip to retrieve results in chunks.

Security Considerations

  • Be cautious when performing Update or Delete operations. A broad filter without restrictions can modify or remove many documents unexpectedly.
  • Keep your MongoDB Connection credentials secure in the Nappai panel. Never share connection strings or passwords.
  • Use the Upsert feature wisely to avoid accidentally creating duplicate documents when an update was intended.