DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Migrating MuleSoft System API to AWS Lambda (Part 1)
  • Java and MongoDB Integration: A CRUD Tutorial [Video Tutorial]
  • MongoDB to Couchbase for Developers, Part 1: Architecture
  • SharePoint Integration With MuleSoft

Trending

  • MCP Servers: The Technical Debt That Is Coming
  • Event Driven Architecture (EDA) - Optimizer or Complicator
  • Rust, WASM, and Edge: Next-Level Performance
  • Scaling Microservices With Docker and Kubernetes on Production
  1. DZone
  2. Data Engineering
  3. Databases
  4. How to Integrate MongoDB With MuleSoft (Mule 4)

How to Integrate MongoDB With MuleSoft (Mule 4)

Get your NoSQL on.

By 
Nagaraju Kshathriya user avatar
Nagaraju Kshathriya
·
Jan. 16, 21 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
7.5K Views

Join the DZone community and get the full member experience.

Join For Free

In this blog, we will demonstrate how to integrate MongoDB with MuleSoft and also demonstrate a few operations with simple examples, such as creating collections, inserting documents, etc.

Before getting started, make sure that you have access to a MongoDB cluster with write permissions or refer to our blog if you’d like to install MongoDB on a Windows machine. 

What Is MongoDB?

MongoDB is an open-source, document-oriented database that stores data in the form of documents (key and value pairs). For more information, visit our MongoDB Hub or official MongoDB documentation.

Integrate MongoDB With MuleSoft

Follow the steps below to integrate MongoDB with MuleSoft and perform some basic MongoDB operations. 

MongoDB Global Configuration 

First, create a MongoDB Global configuration as shown below: 

Step 1: Add the required libraries. To add the libraries, click on Configure and select Add recommended libraries. 

Step 2: Once you added the required libraries, now you will need to add a connection string.

Note: we have selected the connection type Connection string. If you make the connection type Connection, then the configuration will be different. 

The connection string syntax is: 

mongodb://username:password@host:port/database

If you are connecting to a cluster, then the syntax is: 

mongodb+srv://username:password@clusterURL/database_name


Create Collection

First, let’s create a collection called users in the vanchiv database.

To create a collection, simply drag and drop the create collection operation and configure as shown below:

Now run the application and verify whether the collection is created or not. 

> show collections
users 

Insert Document

Once you have created the collection, insert a document into it.

To insert documents, drag and drop the insert document and configure as shown below:

The sample input payload is: 

{    
     "userid": "1",    
     "username": "NaGG"
}

Now run the application and verify whether the document is inserted or not. 

> db.users.find()
{ "_id" : ObjectId("6001b281b1d1732597ace274"), "userid" : "1", "username" : "NaGG" } 

Great! There you can see the document has been inserted into users collection. Remember, MongoDB will create a unique id for each document  "_id" : ObjectId("6001b281b1d1732597ace274"). Read my introduction to MongoDB to learn more.

Mule also sends a response like the one below for the insert document operation.

{    
    "userid": "1",    
    "username": "NaGG",    
        "_id": {        "$oid": "6001b281b1d1732597ace274"    }
}

We hope this blog helped you to integrate MongoDB with MuleSoft and perform some basic operations. 

There are many ways you can use MongoDB operations. We will cover each operation in separate blogs.

MongoDB Integration MuleSoft Database Document

Published at DZone with permission of Nagaraju Kshathriya. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Migrating MuleSoft System API to AWS Lambda (Part 1)
  • Java and MongoDB Integration: A CRUD Tutorial [Video Tutorial]
  • MongoDB to Couchbase for Developers, Part 1: Architecture
  • SharePoint Integration With MuleSoft

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!