Back to Integrations
integrationMongoDB node
integrationOpenAI node

MongoDB and OpenAI integration

Save yourself the work of writing custom integrations for MongoDB and OpenAI and use n8n instead. Build adaptable and scalable Development, Data & Storage, AI, and Langchain workflows that work with your technology stack. All within a building experience you will love.

How to connect MongoDB and OpenAI

  • Step 1: Create a new workflow
  • Step 2: Add and configure nodes
  • Step 3: Connect
  • Step 4: Customize and extend your integration
  • Step 5: Test and activate your workflow

Step 1: Create a new workflow and add the first step

In n8n, click the "Add workflow" button in the Workflows tab to create a new workflow. Add the starting point – a trigger on when your workflow should run: an app event, a schedule, a webhook call, another workflow, an AI chat, or a manual trigger. Sometimes, the HTTP Request node might already serve as your starting point.

MongoDB and OpenAI integration: Create a new workflow and add the first step

Step 2: Add and configure MongoDB and OpenAI nodes

You can find MongoDB and OpenAI in the nodes panel. Drag them onto your workflow canvas, selecting their actions. Click each node, choose a credential, and authenticate to grant n8n access. Configure MongoDB and OpenAI nodes one by one: input data on the left, parameters in the middle, and output data on the right.

MongoDB and OpenAI integration: Add and configure MongoDB and OpenAI nodes

Step 3: Connect MongoDB and OpenAI

A connection establishes a link between MongoDB and OpenAI (or vice versa) to route data through the workflow. Data flows from the output of one node to the input of another. You can have single or multiple connections for each node.

MongoDB and OpenAI integration: Connect MongoDB and OpenAI

Step 4: Customize and extend your MongoDB and OpenAI integration

Use n8n's core nodes such as If, Split Out, Merge, and others to transform and manipulate data. Write custom JavaScript or Python in the Code node and run it as a step in your workflow. Connect MongoDB and OpenAI with any of n8n’s 1000+ integrations, and incorporate advanced AI logic into your workflows.

MongoDB and OpenAI integration: Customize and extend your MongoDB and OpenAI integration

Step 5: Test and activate your MongoDB and OpenAI workflow

Save and run the workflow to see if everything works as expected. Based on your configuration, data should flow from MongoDB to OpenAI or vice versa. Easily debug your workflow: you can check past executions to isolate and fix the mistake. Once you've tested everything, make sure to save your workflow and activate it.

MongoDB and OpenAI integration: Test and activate your MongoDB and OpenAI workflow

Content farming - : AI-powered blog automation for WordPress

==🔥 Upgrade to V4==
We’ve released Version 4 of our AI Powered Blog Automation workflow. We heard your complains and made a complete redesign built for serious content creators.

ChatGPT 5, Inbound Links, Verified Outbound Links,YOAST seo integration, Company profile, higher SEO ranking, banner images using companys mascot, FAQ sections and conclusions, 35% cost reduction,

📝 Read the New Articles published by Content Farming v4

🛒 View the updated and improved v4 workflow

👻 No technical experience ? use Ghost.Blog

Content Farming V2
AI Powered Blog Automation for WordPress

This workflow automatically generates and publishes 10 blog posts per day to a WordPress site. It collects tech-related news articles, filters and analyzes them for relevance, expands them with research, generates SEO-optimized long-form articles using AI, creates a matching image using Leonardo AI, and publishes them via the WordPress REST API. Every step is tracked and stored in MongoDB for reference and performance tracking.

You can see the demo results for the AI based articles here: Emp0 Articles

How it works

A scheduler runs daily to fetch the latest news from RSS feeds including BBC, TechCrunch, Wired, MIT Tech Review, HackerNoon, and others.
The RSS data is normalized and filtered to include only articles published within the past 24 hours.
Each article is passed through an OpenAI-powered classifier to check for relevance to predefined user topics like AI, robotics, or tech policy.
Relevant articles are then aggregated, researched, and summarized with supporting sources and citations.
An AI agent generates five long-tail SEO blog title ideas, ranks them by uniqueness and performance score, and selects the top one.
A blog outline is created including H1 and H2 headers, keyword targeting, content structure, and featured snippet optimization.
A full-length article (1000 to 1500 words) is generated based on the outline, with analogies, citations, examples, and keyword density maintained.
SEO metadata is produced including meta title, description, image alt text, slug, and a readability audit.
An AI-generated image is created based on the blog theme using Leonardo AI, enhanced for emotional storytelling and visual consistency.
The blog article, metadata, and image are uploaded to WordPress as a draft, the image is attached, Yoast SEO metadata is set, and the article is published.

All outputs including article versions, metadata, generation steps, and final blog URLs are stored in MongoDB to allow for future analytics and feedback.

Requirements

To run this project, you need accounts and API access for the following:

Tool Purpose Notes
OpenAI Used for blog classification, generation, summarization, SEO Around $0.20 per day, using GPT-4o-mini. Estimated monthly: $6
MongoDB Stores data flexibly including drafts, titles, metadata, logs Free tier on MongoDB Atlas offers 512 MB, enough for 64,000 articles
Leonardo AI Generates featured images for blog articles $9 for 3500 credits, $5 monthly top-up needed for 300 images
WordPress Final publishing platform via REST API Hosted on Hostinger for $15/year including domain

Setup Instructions

Import the provided JSON file into your n8n instance.
Configure these credentials in n8n:
OpenAI API key
MongoDB Atlas connection string
HTTP Header Auth for Leonardo AI
WordPress REST API credentials
Modify the classifier and prompt nodes to reflect your preferred content themes.
Adjust scheduler nodes if you want to change post frequency or publishing times.
Run the n8n instance continuously using Docker, PM2, or hosted automation platform.

Cost Estimate

Component Daily Usage Monthly Cost Estimate
OpenAI 10 posts per day ~$6
Leonardo AI 10 images per day (15 credits each) ~$14 (9 base + 5 top-up)
MongoDB Free up to 512 MB $0
WordPress Hosting and domain ~$1.25
Total ~$21/month

Observations and Learnings

This system can scale daily article publishing with zero manual effort. However, current limitations include inconsistent blog length and occasional coherence issues. To address this, I plan to build a feedback loop within the workflow:

An SEO Commentator Agent will assess keyword strength, structure, and discoverability.
An Editor-in-Chief Agent will review tone, clarity, and narrative structure.
Both agents will loop back suggestions to the content generator, improving each draft until it meets human-level standards.

The final goal is to consistently produce high-quality, readable, SEO-optimized content that is indistinguishable from human writing.

Nodes used in this workflow

Popular MongoDB and OpenAI workflows

+5

Content farming - : AI-powered blog automation for WordPress

==🔥 Upgrade to V4== We’ve released Version 4 of our AI Powered Blog Automation workflow. We heard your complains and made a complete redesign built for serious content creators. ChatGPT 5, Inbound Links, Verified Outbound Links,YOAST seo integration, Company profile, higher SEO ranking, banner images using companys mascot, FAQ sections and conclusions, 35% cost reduction, 📝 Read the New Articles published by Content Farming v4 🛒 View the updated and improved v4 workflow 👻 No technical experience ? use Ghost.Blog Content Farming V2 AI Powered Blog Automation for WordPress This workflow automatically generates and publishes 10 blog posts per day to a WordPress site. It collects tech-related news articles, filters and analyzes them for relevance, expands them with research, generates SEO-optimized long-form articles using AI, creates a matching image using Leonardo AI, and publishes them via the WordPress REST API. Every step is tracked and stored in MongoDB for reference and performance tracking. You can see the demo results for the AI based articles here: Emp0 Articles How it works A scheduler runs daily to fetch the latest news from RSS feeds including BBC, TechCrunch, Wired, MIT Tech Review, HackerNoon, and others. The RSS data is normalized and filtered to include only articles published within the past 24 hours. Each article is passed through an OpenAI-powered classifier to check for relevance to predefined user topics like AI, robotics, or tech policy. Relevant articles are then aggregated, researched, and summarized with supporting sources and citations. An AI agent generates five long-tail SEO blog title ideas, ranks them by uniqueness and performance score, and selects the top one. A blog outline is created including H1 and H2 headers, keyword targeting, content structure, and featured snippet optimization. A full-length article (1000 to 1500 words) is generated based on the outline, with analogies, citations, examples, and keyword density maintained. SEO metadata is produced including meta title, description, image alt text, slug, and a readability audit. An AI-generated image is created based on the blog theme using Leonardo AI, enhanced for emotional storytelling and visual consistency. The blog article, metadata, and image are uploaded to WordPress as a draft, the image is attached, Yoast SEO metadata is set, and the article is published. All outputs including article versions, metadata, generation steps, and final blog URLs are stored in MongoDB to allow for future analytics and feedback. Requirements To run this project, you need accounts and API access for the following: | Tool | Purpose | Notes | |--------------|------------------------------------------------------------------|-----------------------------------------------------------------------| | OpenAI | Used for blog classification, generation, summarization, SEO | Around $0.20 per day, using GPT-4o-mini. Estimated monthly: $6 | | MongoDB | Stores data flexibly including drafts, titles, metadata, logs | Free tier on MongoDB Atlas offers 512 MB, enough for 64,000 articles | | Leonardo AI | Generates featured images for blog articles | $9 for 3500 credits, $5 monthly top-up needed for 300 images | | WordPress | Final publishing platform via REST API | Hosted on Hostinger for $15/year including domain | Setup Instructions Import the provided JSON file into your n8n instance. Configure these credentials in n8n: OpenAI API key MongoDB Atlas connection string HTTP Header Auth for Leonardo AI WordPress REST API credentials Modify the classifier and prompt nodes to reflect your preferred content themes. Adjust scheduler nodes if you want to change post frequency or publishing times. Run the n8n instance continuously using Docker, PM2, or hosted automation platform. Cost Estimate | Component | Daily Usage | Monthly Cost Estimate | |---------------|------------------------------|------------------------| | OpenAI | 10 posts per day | ~$6 | | Leonardo AI | 10 images per day (15 credits each) | ~$14 (9 base + 5 top-up) | | MongoDB | Free up to 512 MB | $0 | | WordPress | Hosting and domain | ~$1.25 | | Total | | ~$21/month | Observations and Learnings This system can scale daily article publishing with zero manual effort. However, current limitations include inconsistent blog length and occasional coherence issues. To address this, I plan to build a feedback loop within the workflow: An SEO Commentator Agent will assess keyword strength, structure, and discoverability. An Editor-in-Chief Agent will review tone, clarity, and narrative structure. Both agents will loop back suggestions to the content generator, improving each draft until it meets human-level standards. The final goal is to consistently produce high-quality, readable, SEO-optimized content that is indistinguishable from human writing.

Document Q&A System with Voyage-Context-3 Embeddings and MongoDB Atlas

On my never-ending quest to find the best embeddings model, I was intrigued to come across Voyage-Context-3 by MongoDB and was excited to give it a try. This template implements the embedding model on a Arxiv research paper and stores the results in a Vector store. It was only fitting to use Mongo Atlas from the same parent company. This template also includes a RAG-based Q&A agent which taps into the vector store as a test to helps qualify if the embeddings are any good and if this is even noticeable. How it works This template is split into 2 parts. The first part being the import of a research document which is then chunked and embedded into our vector store. The second part builds a RAG-based Q&A agent to test the vector store retrieval on the research paper. Read the steps for more details. How to use First ensure you create a Voyage account voyageai.com and a MongoDB database ready. Start with Step 1 and fill in the "Set Variables" node and Click on the Manual Execute Trigger. This will take care of populating the vector store with the research paper. To use the Q&A agent, it is required to publish the workflow to access the public chat interface. This is because "Respond to Chat" works best in this mode and not in editor mode. To use for your own document, edit the "Set Variables" node to define the URL to your own document. This embeddings approach should work best on larger documents. Requirements Voyageai.com account for embeddings. You may need to add credit to get a reasonable RPM for this workflow. MongoDB database either self-hosted or online at https://www.mongodb.com. OpenAI account for RAG Q&A agent. Customising this workflow The Voyage embeddings work with any vector store so feel free to swap out to other such as Qdrant or Pinecone if you're not a fan of MongoDB Atlas. If you're feeling brave, instead of the 3 sequential pages setup I have, why not try the whole document! Fair warning that you may hit memory problems if your instance isn't sufficiently sized - but if it is, go head and share the results!

Build your own MongoDB and OpenAI integration

Create custom MongoDB and OpenAI workflows by choosing triggers and actions. Nodes come with global operations and settings, as well as app-specific parameters that can be configured. You can also use the HTTP Request node to query data from any app or service with a REST API.

MongoDB supported actions

Create
Drop
List
Update
Aggregate
Aggregate documents
Delete
Delete documents
Find
Find documents
Find And Replace
Find and replace documents
Find And Update
Find and update documents
Insert
Insert documents
Update
Update documents

OpenAI supported actions

Message a Model
Generate a model response with GPT 3, 4, 5, etc. using Responses API
Classify Text for Violations
Check whether content complies with usage policies
Analyze Image
Take in images and answer questions about them
Generate an Image
Creates an image from a text prompt
Edit Image
Edit an image
Generate Audio
Creates audio from a text prompt
Transcribe a Recording
Transcribes audio into text
Translate a Recording
Translates audio into text in English
Delete a File
Delete a file from the server
List Files
Returns a list of files that belong to the user's organization
Upload a File
Upload a file that can be used across various endpoints
Create
Create a conversation
Get
Get a conversation
Remove
Remove a conversation
Update
Update a conversation
Generate
Creates a video from a text prompt

MongoDB and OpenAI integration details

Use case

Save engineering resources

Reduce time spent on customer integrations, engineer faster POCs, keep your customer-specific functionality separate from product all without having to code.

Learn more

FAQs

  • Can MongoDB connect with OpenAI?

  • Can I use MongoDB’s API with n8n?

  • Can I use OpenAI’s API with n8n?

  • Is n8n secure for integrating MongoDB and OpenAI?

  • How to get started with MongoDB and OpenAI integration in n8n.io?

Need help setting up your MongoDB and OpenAI integration?

Discover our latest community's recommendations and join the discussions about MongoDB and OpenAI integration.
Artem
João Textor
sérgio eduardo floresta filho
Andrew adawdad
PinkFloyd

Looking to integrate MongoDB and OpenAI in your company?

Over 3000 companies switch to n8n every single week

Why use n8n to integrate MongoDB with OpenAI

Build complex workflows, really fast

Build complex workflows, really fast

Handle branching, merging and iteration easily.
Pause your workflow to wait for external events.

Code when you need it, UI when you don't

Simple debugging

Your data is displayed alongside your settings, making edge cases easy to track down.

Use templates to get started fast

Use 1000+ workflow templates available from our core team and our community.

Reuse your work

Copy and paste, easily import and export workflows.

Implement complex processes faster with n8n

red iconyellow iconred iconyellow icon