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
Newsletter
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

  • 5 Mistakes Companies Make When Working With Staff Engineers
  • The Self-Hosting Math Changed While We Were Still Arguing About Sovereignty
  • PWA on iOS, Part 3: Chrome on iPhone Is WebKit Too. How One Engine Sets the Rules for PWAs on iOS
  • How to Hide Sensitive Information Before You Share a File

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  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
·
Jan. 16, 21 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
8.0K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • 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