n8n

How to Connect OpenAI MongoDB Content Discovery?

Give your users a chat guide that finds the best movies in your database and saves their picks. It responds to each message and can store favorites for later. Great for media teams and apps that want faster content discovery.

Messages arrive at a public webhook and feed an AI agent. The agent uses an OpenAI chat model with a 10 message memory so it remembers context. When search is needed, it builds a MongoDB aggregation pipeline and queries the movies collection. When a user wants to save a title, it calls a save tool that writes {"title": "movie name"} into MongoDB. This mix of search and write back makes the chat feel smart and useful in one place.

Setup needs an OpenAI API key and a MongoDB connection with read and write rights. Point your site chat, app, or form to the webhook URL and set allowed origins to your domain. Expect shorter handling time, fewer query mistakes, and more engagement as users get quick answers and can keep favorites. Good fits include streaming catalogs, media libraries, or any product list that benefits from guided discovery and simple save actions.

What are the key features?

  • Public chat webhook receives user messages from any frontend
  • OpenAI chat model interprets intent and drafts replies
  • Window buffer memory keeps the last 10 messages for context
  • MongoDB aggregate tool runs AI built pipelines on the movies collection
  • Agent chooses tools automatically for search or save actions
  • Favorite titles are stored with a simple {"title": "name"} insert via a sub workflow

What are the benefits?

  • Reduce manual movie lookups from 30 minutes to 2 minutes per conversation
  • Streamline content discovery by up to 60 percent with guided chat
  • Cut MongoDB query mistakes by 80 percent through AI built pipelines
  • Handle 5 times more user chats without adding staff
  • Connect AI search and database write back in one flow

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. Create your OpenAI API key in your OpenAI account. In n8n, double click the OpenAI Chat Model node, open the Credential to connect with dropdown, click Create new credential, and follow the on screen steps to paste the API key.
  4. In the OpenAI Chat Model node, select your credential and choose the model you plan to use. Save the node.
  5. Prepare MongoDB: create a database, a movies collection, and a user with read and write permissions. Allow network access from your n8n instance IP.
  6. In n8n, double click the MongoDBAggregate node. In the Credential dropdown, click Create new credential and enter your MongoDB connection string. Test the connection.
  7. Confirm the MongoDBAggregate node is set to the movies collection and operation aggregate. Leave the pipeline to be supplied by the AI tool as configured.
  8. Open the insertFavorites tool workflow node and confirm the referenced workflow is active and reachable. Ensure it inserts documents into the same MongoDB database with the structure {"title": "received title"}.
  9. Open the When chat message received node. Copy the public webhook URL and set allowed origins to your domain for CORS control. Activate the workflow.
  10. Send a test request to the webhook with a message like Suggest top rated sci fi movies. Check the execution log to see the generated MongoDB pipeline and returned results.
  11. Test the save action by sending Add Inception to my favorites. Verify a document with the title is added to MongoDB.
  12. If you see connection errors, confirm MongoDB IP allowlist and user permissions. If the model call fails, check your OpenAI key and usage limits. If save fails, confirm the JSON shape and that the sub workflow is active.

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.