MongoDB Movie Recommendation AI Agent

MongoDB Agent

An intelligent movie recommendation system powered by OpenAI and MongoDB, supporting natural language queries of the movie database, personalized recommendations, and watchlist management.

8 NodesDeveloper ToolsAI chatbot MongoDB integration movie recommendation

Workflow Overview

This is an AI-powered agent workflow built on OpenAI and MongoDB for movie recommendation and management. The workflow receives chat messages, queries movie data using MongoDB's aggregation framework, and supports storing users' favorite movies back into the database.

Workflow Name

MongoDB Agent

Core Features

  1. Intelligent Conversational Interaction: Receives user movie queries via a chat interface
  2. MongoDB Data Querying: Retrieves relevant information from the MongoDB movie database using aggregation pipelines
  3. Movie Recommendations: Provides personalized movie suggestions based on user preferences
  4. Favorites Management: Allows users to save favorite movies to the database

Node Details

1. When chat message received (Chat Message Trigger)

  • Type: @n8n/n8n-nodes-langchain.chatTrigger
  • Function: Entry point of the workflow, receiving user chat messages via webhook
  • Configuration:
    • Mode: Webhook (publicly accessible)
    • Accepts requests from all origins (allowedOrigins: "*")

2. AI Agent - Movie Recommendation (AI Movie Recommendation Agent)

  • Type: @n8n/n8n-nodes-langchain.agent
  • Function: Core AI agent coordinating the entire workflow logic
  • Prompt Instructions:
    • Acts as a movie context assistant
    • Uses the MongoDBAggregate tool for searching
    • Must provide an array of MongoDB aggregation pipeline code
    • Only uses the insertFavorite tool to save favorites upon explicit user confirmation

3. OpenAI Chat Model

  • Type: @n8n/n8n-nodes-langchain.lmChatOpenAi
  • Function: Provides AI language understanding and generation capabilities
  • Credentials: Connected to the OpenAI API

4. Window Buffer Memory

  • Type: @n8n/n8n-nodes-langchain.memoryBufferWindow
  • Function: Maintains conversation context
  • Configuration: Keeps a context window of the most recent 10 messages

5. MongoDBAggregate (MongoDB Aggregation Tool)

  • Type: n8n-nodes-base.mongoDbTool
  • Function: Executes MongoDB aggregation queries
  • Operation: Aggregate
  • Collection: movies
  • Document Structure: Contains the following fields
    • plot: Brief movie synopsis
    • genres: Movie genres (array)
    • runtime: Runtime duration
    • cast: Cast list
    • poster: Poster URL
    • title: Movie title
    • fullplot: Full plot description
    • languages: Languages
    • released: Release date
    • directors: Directors
    • rated: Rating classification
    • awards: Awards information
    • year: Year
    • imdb: IMDb rating details

6. insertFavorite (Insert Favorite Tool)

  • Type: @n8n/n8n-nodes-langchain.toolWorkflow
  • Function: Invokes a sub-workflow to insert the user's favorite movie into the database
  • Workflow ID: 6QuKnOrpusQVu66Q (insertMongoDB)
  • Data Structure: {"title": "Movie Title"}

7–8. Sticky Note

  • Function: Provides documentation and process explanations for the workflow

Workflow Process

  1. Message Reception: User sends a movie-related query through the chat interface
  2. AI Analysis: OpenAI model interprets user intent and requirements
  3. Data Retrieval: Invokes the MongoDBAggregate tool to query movie data as needed
  4. Result Enhancement: AI agent processes query results and generates user-friendly responses
  5. Favorite Saving: If the user confirms liking a movie, the insertFavorite tool is invoked to save it
  6. Context Maintenance: Window Buffer Memory ensures conversational continuity

Connections

  • When chat message receivedAI Agent - Movie Recommendation
  • OpenAI Chat ModelAI Agent - Movie Recommendation (language model)
  • Window Buffer MemoryAI Agent - Movie Recommendation (memory)
  • MongoDBAggregateAI Agent - Movie Recommendation (tool)
  • insertFavoriteAI Agent - Movie Recommendation (tool)

Technical Characteristics

  1. Autonomous Agent Architecture: AI independently decides when and which tools to use
  2. Context Preservation: Maintains conversation continuity through windowed memory
  3. Flexible Querying: Supports complex MongoDB aggregation pipeline queries
  4. Bidirectional Interaction: Capable of both reading from and writing to the database
  5. Public Accessibility: Exposed via webhook for integration with external systems

Use Cases

  • Movie recommendation chatbot
  • Intelligent movie database query system
  • Personalized movie favorites management
  • Movie information retrieval assistant

Status

  • Active: true (workflow is activated)
  • Execution Order: v1

Tech Stack

  • AI Framework: LangChain
  • Language Model: OpenAI
  • Database: MongoDB
  • Platform: n8n workflow automation