MongoDB
Learn how to use the MongoDB node in StackAI to query your MongoDB database, including required inputs, configuration, and output examples.
The MongoDB Node in StackAI allows you to query a MongoDB database directly from your workflow. This node is ideal for retrieving data from your collections using flexible filters, making it easy to integrate database results into your AI-powered automations.
How to use it?
To use the MongoDB node, you need to provide the following required inputs and configurations:
Database Name (Required Configuration)
Description: The name of the MongoDB database you want to query.
Example: "customer_data"
Collection Name (Required Configuration)
Description: The name of the collection within the database to query.
Example: "orders"
Filter (Required Input)
Description: The MongoDB query filter in JSON format. This determines which documents are returned.
Example:
To find all orders for a specific user: {"user_id": "499484bb-fd54-4fb0-93e5-4ad98bdcdf94"}
To find users aged 18 or older: {"age": {"$gte": 18}}
To find orders with status "active" or "pending": {"status": {"$in": ["active", "pending"]}}
To find documents created after a certain date: {"created_at": {"$gte": "2024-01-01T00:00:00Z"}}
Example of Usage
Suppose you want to retrieve all active orders from the "orders" collection in the "customer_data" database:
Database Name: "customer_data" (Required)
Collection Name: "orders" (Required)
Filter: {"status": "active"} (Required)
Expected Output
Results (Required Output)
Description: An array of objects, each representing a document from the collection that matches the filter.
Example:
{ "results": [ { "order_id": "12345", "user_id": "abcde", "status": "active", "amount": 99.99 }, { "order_id": "12346", "user_id": "fghij", "status": "active", "amount": 49.99 } ] }
Available Actions
Query MongoDB
Description: Retrieve documents from a specified database and collection using a JSON filter.
Required Inputs:
Database Name (string, required)
Collection Name (string, required)
Filter (string, required; JSON format)
Output:
Results (array of objects, required): The documents matching your query.
Summary
The MongoDB node in StackAI is a powerful tool for querying your MongoDB collections. By specifying the database, collection, and filter, you can retrieve exactly the data you need and use it in your automated workflows.
Last updated
Was this helpful?