n8n

How to Automate OpenAI MongoDB Movie Recommendations?

Turn chat messages into live movie picks from your MongoDB data. Great for marketing and content teams that want to guide viewers and capture favorites in one place. It delivers fast answers and saves user choices for follow up campaigns.

A public webhook receives each chat message. The OpenAI chat model understands the intent, while a short memory keeps the last ten turns so replies stay on topic. The agent can run a MongoDB aggregation on the movies collection using a pipeline it builds from the question, like filter by rating or genre. It can also call a separate insert flow to save a favorite title in the database. The result is a smart chat that searches your catalog and logs interest in the same thread.

You need an OpenAI API key and a MongoDB connection string. Point your chat UI to the webhook and confirm the insert tool targets the right collection and title field. Expect faster curation, new first party data, and clear signals for remarketing and email promos.

What are the key features?

  • Webhook chat trigger receives user messages from any front end
  • OpenAI chat model turns plain questions into clear, helpful replies
  • Memory window keeps the last 10 messages to maintain context
  • MongoDB Aggregate tool runs AI built pipelines on the movies collection
  • AI agent selects the right tool based on user intent
  • InsertFavorites tool workflow writes a favorite title into MongoDB
  • Run view and logs in n8n help with testing and monitoring

What are the benefits?

  • Reduce manual curation from 2 hours to 5 minutes per campaign
  • Streamline search and save steps by about 80 percent
  • Improve data quality by removing up to 90 percent of copy paste errors
  • Handle 10 times more chat requests compared to manual replies
  • Connect OpenAI and MongoDB in one flow for unified insights

How do you set it up?

  1. Import the template into n8n: Create a new workflow in n8n > Click the three dots menu > Select 'Import from File' > Choose the downloaded JSON file.
  2. You'll need accounts with OpenAI and MongoDB. See the Tools Required section above for links to create accounts with these services.
  3. In n8n, open the OpenAI Chat Model node. In the Credential to connect with dropdown, click Create new credential, add your OpenAI API key from the OpenAI API page, and save.
  4. Open the MongoDBAggregate node. In the Credential to connect with dropdown, click Create new credential, enter your MongoDB connection string, database, and authentication details, then save.
  5. Confirm the MongoDBAggregate node points to the movies collection and uses the aggregate operation. Leave the pipeline field controlled by AI as designed.
  6. Open the AI Agent node and review the prompt text. Make sure it instructs the agent to send a proper MongoDB aggregation pipeline and to use the insert tool only for saving favorites.
  7. Check the Window Buffer Memory node and keep the context length at 10 to maintain short but useful chat history.
  8. Open the insertFavorites tool workflow node. Update the linked workflow ID if you cloned or renamed the insert flow. Ensure it accepts an input with the structure {"title":"value"} and writes to the correct MongoDB collection.
  9. Open the When chat message received node and copy the webhook URL. If you host a web chat, point it to this URL. Keep allowed origins set as needed for your front end.
  10. Test the flow by sending a message like Best rated action movies to the webhook. You should see an aggregate query run and a reply with movie picks.
  11. Test the save path by sending Save this as favorite with a title. Check MongoDB to confirm the document was inserted with the correct title field.
  12. If you see CORS issues, adjust allowedOrigins in the trigger. If MongoDB queries fail, verify network rules, credentials, and that the movies documents include fields like rating and genre.

Tools Required

$24 / mo or $20 / mo billed annually to use n8n in the cloud. However, the local or self-hosted n8n Community Edition is free.

MongoDB

Sign up

Atlas Free (M0): $0 / mo (free forever)

OpenAI

Sign up

Pay-as-you-go: GPT-5 at $1.25 per 1M input tokens and $10 per 1M output tokens

Similar Templates

Join Futurise to access 1,200+ automation templates

Get instant access to ready-made automation workflows for n8n, Make.com, AI agents, and more. Download, customise, and deploy in minutes.