Build an intelligent n8n workflow using an AI agent to dynamically query MongoDB for movie recommendations using aggregation pipelines, integrating the OpenAI n8n node for advanced logic.
Download this n8n workflow template and start using it instantly.
Developers and engineers using MongoDB for application data.
Data scientists interested in connecting large datasets to intelligent AI agents.
n8n users looking for advanced examples of LangChain Agent implementation.
Anyone needing an intelligent system that executes dynamic database queries based on conversational input.
This advanced n8n workflow establishes a sophisticated conversational AI agent capable of interacting with a MongoDB database. Unlike static queries, this solution leverages the intelligence of the OpenAI n8n node (acting as the Language Model) to dynamically generate and execute complex MongoDB aggregation pipelines.
The core value of this n8n template lies in its ability to understand natural language requests (e.g., 'Find me highly rated Western movies from the 1950s') and autonomously translate that into a functional $aggregate query via the specialized MongoDBAggregate n8n node. Furthermore, the agent is equipped with a second tool—an insertFavorite workflow tool—allowing users to store confirmed movie preferences back into the database, completing the feedback loop. This powerful application demonstrates the seamless integration of LLMs, proprietary databases, and core n8n flow control.
This automation begins instantly upon an external command via the When chat message received n8n trigger. This interactive n8n trigger passes the user's conversational input directly to the core of the system, the AI Agent - Movie Recommendation.
When chat message received n8n trigger (a webhook listener) receives a message (e.g., a recommendation request or a request to save a favorite).AI Agent - Movie Recommendation n8n node processes the input. It uses the OpenAI Chat Model n8n node as its brain and maintains conversational history via the Window Buffer Memory.MongoDBAggregate tool is needed. It then instructs the AI to generate a precise MongoDB aggregation pipeline query based on the database schema provided in the tool description.MongoDBAggregate n8n node executes the dynamically generated pipeline against the movies collection in MongoDB, fetching relevant context.insertFavorite n8n node (a workflow tool) and structures the appropriate JSON payload for insertion.To deploy this comprehensive n8n workflow, follow these steps:
OpenAI Chat Model n8n node and set up your OpenAI API Key credential. This is essential for the language model functionality.MongoDBAggregate n8n node and configure your MongoDB credential, ensuring it points to the database instance containing your 'movies' collection.insertFavorite n8n node is configured as a Workflow Tool. You must ensure the target workflow ID (6QuKnOrpusQVu66Q in the example) points to a separate working n8n template designed to handle the MongoDB insertion operation.When chat message received n8n trigger will provide a public webhook URL which can be used to initiate interactions.The following specialized n8n node components drive this AI automation:
When chat message received (n8n trigger): Acts as the entry point, listening for incoming chat messages via a public webhook. This powerful n8n trigger facilitates real-time, conversational interaction.
AI Agent - Movie Recommendation (LangChain Agent n8n node): The orchestrator. It uses a defined prompt to guide its behavior, specifying its ability to query context using MongoDBAggregate and save favorites using insertFavorite.
OpenAI Chat Model (LangChain n8n node): Provides the necessary reasoning power for the Agent, allowing it to interpret requests and generate appropriate MongoDB queries.
Window Buffer Memory (LangChain n8n node): Essential for maintaining conversational context across multiple interactions, enabling the AI agent to remember previous parts of the discussion.
MongoDBAggregate (MongoDB Tool n8n node): This highly customized n8n node allows the Agent to use the $fromAI expression to dynamically generate the MongoDB aggregation pipeline. It provides the AI with the database document schema for context, ensuring accurate query construction.
insertFavorite (Workflow Tool n8n node): This n8n node represents an external workflow call. The AI Agent uses this tool exclusively when the user confirms a favorite movie title, delegating the insertion task to a secondary, specialized n8n workflow.
Use this powerful n8n workflow template to monetize your private Ollama Large Language Models (LLMs) using the x402 payment protocol and the 1Shot API. This n8n workflow validates all transactions.

Secure and monetize your API services instantly using the x402 payment protocol within a custom n8n workflow. This n8n template utilizes the 1Shot API node for robust crypto payment verification and processing.

Use this powerful n8n workflow to extract complex Monday.com data, including nested subitems, linked pulses, and specific column values using custom n8n node logic and JavaScript scripting.

Automate security compliance with this n8n workflow. Monitor inactive AWS IAM users (90+ days) using the AWS n8n node and send instant alerts to Slack. A critical n8n template for DevOps.

Automate Facebook Ad monitoring with this powerful n8n workflow. Use AI agents and Bright Data MCP to scrape ad performance data and send instant Gmail alerts for underperforming campaigns. This n8n workflow template saves time and minimizes missed opportunities.

Use this robust n8n workflow to schedule periodic checks of AWS EC2 instance health. Features include automated self-healing (restarts), detailed logging to Google Sheets, and multi-channel alerts (WhatsApp/Email). Start building with n8n templates today.


Developer imagination == Innovation ✓ Experienced DBA & DevOps engineer & Web Developer. Develop and deploy automation of servers, infrastructure and security to the cloud. Scaling, upgrading and designing Big scaled systems and databases . Specializing in designing and building big data solutions in both RDBMS and NoSql echosystems. Hardworking and innovative personality.







































