MongoDB AI Agent: Intelligent Movie Recommendations

n8n AI Data Management Content Creation

Contributed by Sabrina Ramonov 🍄. From the community directory at agents.sabrina.dev, republished with permission and full credit.

Who is this for?

This workflow is designed for:

- Database administrators and developers working with MongoDB

- Content managers handling movie databases

- Organizations looking to implement AI-powered search and recommendation systems

- Developers interested in combining LangChain, OpenAI, and MongoDB capabilities

What problem does this workflow solve?

Traditional database queries can be complex and require specific MongoDB syntax knowledge. This workflow addresses:

- The complexity of writing MongoDB aggregation pipelines

- The need for natural language interaction with movie databases

- The challenge of maintaining user preferences and favorites

- The gap between AI language models and database operations

What this workflow does

This workflow creates an intelligent agent that:

- Accepts natural language queries about movies

- Translates user requests into MongoDB aggregation pipelines

- Queries a movie database containing detailed information including:

- Plot summaries

- Genre classifications

- Cast and director information

- Runtime and release dates

- Ratings and awards

- Provides contextual responses using OpenAI's language model

- Allows users to save favorite movies to the database

- Maintains conversation context using a window buffer memory

SetupRequired Credentials:

- OpenAI API credentials

- MongoDB connection details

Node Configuration:

- Configure the MongoDB connection in the MongoDBAggregate node

- Set up the OpenAI Chat Model with your API key

- Ensure the webhook trigger is properly configured for receiving chat messages

Database Requirements:

- A MongoDB collection named "movies" with the specified document structure

- Proper indexes for efficient querying

- Appropriate user permissions for read/write operations

How to customize this workflowModify the Document Structure:

- Update the tool description in the MongoDBAggregate node to match your collection schema

- Adjust the aggregation pipeline templates for your specific use case

Enhance the AI Agent:

- Customize the prompt in the "AI Agent - Movie Recommendation" node

- Modify the window buffer memory size based on your context needs

- Add additional tools for more functionality

Extend Functionality:

- Add more MongoDB operations beyond aggregation

- Implement additional workflows for different types of queries

- Create custom error handling and validation

- Add user authentication and rate limiting

Integration Options:

- Connect to external APIs for additional movie data

- Add webhook endpoints for different platforms

- Implement caching mechanisms for frequent queries

- Add data transformation nodes for specific output formats

This workflow serves as a foundation that can be adapted to various use cases beyond movie recommendations, such as e-commerce product search, content management systems, or any scenario requiring intelligent database interaction.

Tools used: OpenAI, MongoDB, LangChain

Download the workflow template (JSON)

Original tutorial

Want this running in your business? KOBA42 builds and operates automations like this one.