MongoDB Agent

Empower your applications with intelligent data retrieval and interaction by deploying the MongoDB Agent workflow. This powerful n8n automation connects OpenAI's advanced language models with your MongoDB database, enabling dynamic, natural language queries and data manipulation. When a chat message is received via the "When chat message received" trigger, an "AI Agent - Movie Recommendation" node processes the input, leveraging an "OpenAI Chat Model" for understanding and response generation. It interacts with your MongoDB database using the "MongoDBAggregate" node to fetch relevant data and can even trigger an "insertFavorite" workflow via an "AI:toolWorkflow" node for specific actions, all while maintaining conversational context with a "Window Buffer Memory". This workflow is ideal for developers building customer support chatbots, data analysts needing quick insights from large datasets, or anyone looking to integrate AI-powered natural language interfaces directly with their MongoDB data, significantly reducing the manual effort of writing complex database queries and enhancing user experience through intuitive interactions.
8 nodesmanual trigger89 views0 copiesData
MongoDBOpenAI

Workflow JSON

{"id": "22PddLUgcjSJbT1w", "meta": {"instanceId": "fa7d5e2425ec76075df7100dbafffed91cc6f71f12fe92614bf78af63c54a61d", "templateCredsSetupCompleted": true}, "name": "MongoDB Agent", "tags": [], "nodes": [{"id": "d8c07efe-eca0-48cb-80e6-ea8117073c5f", "name": "OpenAI Chat Model", "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi", "position": [1300, 560], "parameters": {"options": {}}, "credentials": {"openAiApi": {"id": "", "name": "[Your openAiApi]"}}, "typeVersion": 1}, {"id": "636de178-7b68-429a-9371-41cf2a950076", "name": "MongoDBAggregate", "type": "n8n-nodes-base.mongoDbTool", "position": [1640, 540], "parameters": {"query": "={{ $fromAI(\"pipeline\", \"The MongoDB pipeline to execute\" , \"string\" , [{\"$match\" : { \"rating\" : 5 } }])}}", "operation": "aggregate", "collection": "movies", "descriptionType": "manual", "toolDescription": "Get from AI the MongoDB Aggregation pipeline to get context based on the provided pipeline, the document structure of the documents is : {\n \"plot\": \"A group of bandits stage a brazen train hold-up, only to find a determined posse hot on their heels.\",\n \"genres\": [\n \"Short\",\n \"Western\"\n ],\n \"runtime\": 11,\n \"cast\": [\n \"A.C. Abadie\",\n \"Gilbert M. 'Broncho Billy' Anderson\",\n ...\n ],\n \"poster\": \"...jpg\",\n \"title\": \"The Great Train Robbery\",\n \"fullplot\": \"Among the earliest existing films in American cinema - notable as the ...\",\n \"languages\": [\n \"English\"\n ],\n \"released\": \"date\"\n },\n \"directors\": [\n \"Edwin S. Porter\"\n ],\n \"rated\": \"TV-G\",\n \"awards\": {\n \"wins\": 1,\n \"nominations\": 0,\n \"text\": \"1 win.\"\n },\n \"lastupdated\": \"2015-08-13 00:27:59.177000000\",\n \"year\": 1903,\n \"imdb\": {\n \"rating\": 7.4,"}, "credentials": {"mongoDb": {"id": "", "name": "[Your mongoDb]"}}, "typeVersion": 1.1}, {"id": "e0f248dc-22b7-40a2-a00e-6298b51e4470", "name": "Window Buffer Memory", "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow", "position": [1500, 540], "parameters": {"contextWindowLength": 10}, "typeVersion": 1.2}, {"id": "da27ee52-43db-4818-9844-3c0a064bf958", "name": "When chat message received", "type": "@n8n/n8n-nodes-langchain.chatTrigger", "position": [1160, 400], "webhookId": "0730df2d-2f90-45e0-83dc-609668260fda", "parameters": {"mode": "webhook", "public": true, "options": {"allowedOrigins": "*"}}, "typeVersion": 1.1}, {"id": "9ad79da9-3145-44be-9026-e37b0e856f5d", "name": "insertFavorite", "type": "@n8n/n8n-nodes-langchain.toolWorkflow", "position": [1860, 520], "parameters": {"name": "insertFavorites", "workflowId": {"__rl": true, "mode": "list", "value": "6QuKnOrpusQVu66Q", "cachedResultName": "insertMongoDB"}, "description": "=Use this tool only to add favorites with the structure of {\"title\" : \"recieved title\" }"}, "typeVersion": 1.2}, {"id": "4d7713d1-d2ad-48bf-971b-b86195e161ca", "name": "AI Agent - Movie Recommendation", "type": "@n8n/n8n-nodes-langchain.agent", "position": [1380, 300], "parameters": {"text": "=Assistant for best movies context, you have tools to search using \"MongoDBAggregate\" and you need to provide a MongoDB aggregation pipeline code array as a \"query\" input param. User input and request: {{ $json.chatInput }}. Only when a user confirms a favorite movie use the insert favorite using the \"insertFavorite\" workflow tool of to insertFavorite as { \"title\" : \"<TITLE>\" }.", "options": {}, "promptType": "define"}, "typeVersion": 1.7}, {"id": "2eac8aed-9677-4d89-bd76-456637f5b979", "name": "Sticky Note", "type": "n8n-nodes-base.stickyNote", "position": [880, 300], "parameters": {"width": 216.0875923062025, "height": 499.89779507612025, "content": "## AI Agent powered by OpenAI and MongoDB \n\nThis flow is designed to work as an AI autonomous agent that can get chat messages, query data from MongoDB using the aggregation framework.\n\nFollowing by augmenting the results from the sample movies collection and allowing storing my favorite movies back to the database using an \"insert\" flow. "}, "typeVersion": 1}, {"id": "4d8130fe-4aed-4e09-9c1d-60fb9ac1a500", "name": "Sticky Note1", "type": "n8n-nodes-base.stickyNote", "position": [1300, 720], "parameters": {"content": "## Process\n\nThe message is being processed by the \"Chat Model\" and the correct tool is used according to the message. "}, "typeVersion": 1}], "active": true, "pinData": {}, "settings": {"executionOrder": "v1"}, "versionId": "879aab24-6346-435f-8fd4-3fca856ba64c", "connections": {"insertFavorite": {"ai_tool": [[{"node": "AI Agent - Movie Recommendation", "type": "ai_tool", "index": 0}]]}, "MongoDBAggregate": {"ai_tool": [[{"node": "AI Agent - Movie Recommendation", "type": "ai_tool", "index": 0}]]}, "OpenAI Chat Model": {"ai_languageModel": [[{"node": "AI Agent - Movie Recommendation", "type": "ai_languageModel", "index": 0}]]}, "Window Buffer Memory": {"ai_memory": [[{"node": "AI Agent - Movie Recommendation", "type": "ai_memory", "index": 0}]]}, "When chat message received": {"main": [[{"node": "AI Agent - Movie Recommendation", "type": "main", "index": 0}]]}}}

How to Import This Workflow

  1. 1Copy the workflow JSON above using the Copy Workflow JSON button.
  2. 2Open your n8n instance and go to Workflows.
  3. 3Click Import from JSON and paste the copied workflow.

Don't have an n8n instance? Start your free trial at n8nautomation.cloud

Related Templates

ETL pipeline

Automate your data extraction, transformation, and loading with this robust ETL pipeline, designed to efficiently process and analyze information from various sources. This workflow begins on a schedule, fetching tweets from Twitter/X, then storing them in MongoDB for initial processing. The MongoDB data is then sent to Google Cloud Natural Language for sentiment analysis or entity extraction, with the results subsequently prepared and stored in PostgreSQL. A conditional check on the PostgreSQL data determines whether to send an alert to Slack, ensuring timely notifications for critical insights or anomalies. This powerful automation is ideal for marketing teams monitoring brand sentiment, researchers analyzing public opinion, or businesses tracking competitor activity, providing actionable intelligence without manual data handling. By automating data ingestion, enrichment, and storage, this workflow significantly reduces the time and effort spent on data preparation, allowing teams to focus on analysis and strategic decision-making while ensuring data consistency and accessibility.

9 nodes

SQL agent with memory

Empower your data analysis with the SQL agent with memory workflow, automating the process of querying databases using natural language. This powerful workflow connects OpenAI's advanced language models with your local SQL databases, allowing you to interact with your data through a conversational interface. Initially, the workflow downloads a chinook.zip example database, extracts it, and saves the chinook.db file locally, making it immediately available for querying. The AI Agent, powered by OpenAI Chat Model and supported by a Window Buffer Memory, interprets your natural language questions, translates them into SQL queries, executes them against your local chinook.db, and provides the results back to you. This is incredibly useful for data analysts, business intelligence professionals, or anyone needing quick insights from their databases without writing complex SQL queries, significantly reducing the time and specialized knowledge required for data exploration. By leveraging the Chat Trigger, users can easily initiate conversations and receive immediate, intelligent responses, streamlining data access and accelerating decision-making.

13 nodes

Transcribing Bank Statements To Markdown Using Gemini Vision AI

Automate the tedious process of transcribing bank statements into structured Markdown with this powerful n8n workflow. This solution leverages Google Gemini Vision AI to intelligently extract financial data from PDF bank statements stored in Google Drive, transforming scanned documents into easily parsable text. It begins by fetching a specified bank statement PDF from Google Drive upon manual trigger, then splits the PDF into individual image pages. These images are then resized for optimal AI processing before being fed to Google Gemini Vision AI for transcription. The AI identifies and extracts deposit table rows, and a final AI chain node converts this raw data into a clean, organized Markdown format. This workflow is ideal for financial analysts, small business owners, or anyone needing to quickly digitize and analyze physical bank records, saving significant time and reducing manual data entry errors.

20 nodes

Ready to automate with n8n?

Get affordable managed n8n hosting with 24/7 support.