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
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

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

  • Architecting Zero-Trust AI Agents: How to Handle Data Safely
  • Build a GitHub Slack Bot With AWS Bedrock and MCP, Part 1
  • When One MVP Is Really Four Systems: A Better Way to Plan Multi-Role Apps
  • Securing the AI Host: Spring AI MCP Server Communication With API Keys
  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.9K 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

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

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

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 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook