MuleSoft MongoDB Integration: Using MuleSoft MongoDB Connector to Insert Documents and Find Documents in MongoDB Collection

By | November 7, 2021

MongoDB is a popular and widely used NoSQL database which stores data in the form of documents inside database collections. When implementing integration solutions in Mule 4, MuleSoft MongoDB Integration can be done by using a feature-rich Connector Module provided by MuleSoft. MuleSoft MongoDB Connector is available in AnyPoint Exchange and can be conveniently implemented in message flows in AnyPoint Studio.

In this MuleSoft MongoDB tutorial, you will learn how to use MongoDB Connector in AnyPoint Studio Projects to perform different operations on MongoDB Collection including Create Collection, checking if a collection exists already, inserting documents in MongoDB collection, find documents using search criteria from MongoDB collection.

MuleSoft MongoDB Integration Tutorial Demo Use Case

For this tutorial, a simple use-case is implemented to demonstrate usage of MongoDB operations in AnyPoint Studio projects. The use case is explained below:

We need to implement a simple REST service with HTTP Listener which supports both POST and GET methods (verbs) to save and retrieve data from MongoDB collection respectively. For POST method, service will receive a request with JSON payload containing an array of user objects along with a name of collection to be used. If collection already exists in the database, all users will be added in the collection in the form of documents otherwise, collection will be created and documents will be inserted subsequently.

In case if GET method, documents will be fetched from the collection based on the query parameter provided in the request. A search criteria will be applied to find only specific documents from the collection and fields will be explicitly specified to decide which elements should be returned in the response JSON.

Now that you have use-case clarity, let’s proceed with the implementation of the use-case.

MuleSoft MongoDB Integration Step by Step Tutorial

When you create a project in AnyPoint Studio, by default MongoDB connector is not available. In order to use MongoDB Connector, you need to add MongoDB Module from AnyPoint Exchange. For this purpose, you need to have an account on AnyPoint Platform.

Subsequently, follow all the steps in the below tutorial on TutorialsPedia YouTube Channel where above use-case is implemented and all steps are demonstrated and explained in detail.

Once you have followed above tutorial and implemented the use-case together, you should be comfortable to explore and try other operations as well from MongoDB connector. However, if you face any difficulty and if you are stuck at any step, feel free to comment below to get any advice or assistance.

Ajmal Abbasi

Ajmal Hussain Abbasi is Integration Consultant By Profession with 13+ years experience in Integration domain mainly with TIBCO products. He has extensive practical knowledge of TIBCO Business Works, TIBCO Cloud, TIBCO Flogo, TIBCO Mashery, TIBCO Spotfire, EMS and TIBCO ActiveSpaces. He has worked on a number of highly critical integration projects in various sectors by using his skills in TIBCO Flogo, TIBCO API Management (Mashery), TCI, Tibco Designer, TIBCO Business Studio, Adapters, TIBCO EMS, RV, Administrator, TIBCO BE, TIBCO ActiveSpaces etc. Ajmal Abbasi has experience with MuleSoft ESB as well. Ajmal Abbasi is also experienced in the area of API Management particularly with WSO2 API management platforms. Ajmal Abbasi is also experienced in developing solutions using Core Java and J2EE Technologies. You can contact Ajmal Abbasi for Consultancy, Technical Assistance and Technical Discussions.

More Posts - Website - Facebook - LinkedIn - YouTube

One thought on “MuleSoft MongoDB Integration: Using MuleSoft MongoDB Connector to Insert Documents and Find Documents in MongoDB Collection

Leave a Reply

Your email address will not be published. Required fields are marked *