DZone
Integration Zone
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
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Integration Zone > Accessing MongoDB in Mule Flow

Accessing MongoDB in Mule Flow

In this walkthrough, learn the steps to set up MongoDB to quickly store and retrieve documents from the database through Mule Flow.

Srinu Prasad A user avatar by
Srinu Prasad A
·
Jun. 11, 17 · Integration Zone · Tutorial
Like (1)
Save
Tweet
11.46K Views

Join the DZone community and get the full member experience.

Join For Free

MongoDB is leading open source NoSQL database. In this post, I am going to execute the basic operations to store and retrieve the documents from MongoDB through Mule Flow.

  1. MongoDB Setup.

  2. Configure the MongoDB component in Mule Flow.

  3. Execute the flow to save a document.

  4. Execute the flow to retrieve the document saved.

Set Up

  1. Install the MongoDB that your OS supports.

  2. MongoDB requires a data folder to store its files. The default location for the MongoDB data directory is c:\data\db. So you need to create this folder using the Command Prompt.
            Create the DB using the commands
            C:\>md data
             C:\md data\db

  3. Start the MongoDB server:
    Open new DOS Command prompt as Administrator and Navigate to Mongo DB installation folder: C:\Program Files\MongoDB\Server\3.4\bin > mongod

Configure the MongoDB Component in Mule Flow

1) Add the HTTP Connector and configure the endpoint by providing HOST and PORT details.

2) Add MongoDB component to the flow next to HTTP connector.

3) Optionally, add a logger component to watch the input:

Image title

Configure the MongoDB component as below. 

Provide username, password, database name, and HOST & PORT details.

Image title

Configure the properties of the MongoDB component as follows.

Image title

Now we need to provide the collection name to store the data (here, "developer").

Insert the New Document in the MongoDB Collection

Post the document via an HTTP Post request to the Mule flow through Postman.

Image title

Execute the Flow to Retrieve the Saved Document

To query MongoDB for documents, use the "Find One Document" operation. The flow is as follows:

Image title

The MongoDB configuration details for the retrieval of the document are as follows:

Image title

Query MongoDB through the Postman client as below; the query hits the MongoDB component in the Mule flow:

Image title

The document has been successfully retrieved from MongoDB. Observe the document retrieved through the log statement of the logger component. MongoDB generates a unique ID for each document.

Image title

The MongoDB connector has the capability to store and retrieve documents from the Mule flow efficiently and with minimal configuration. 

MongoDB Flow (web browser) Document

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Making Machine Learning More Accessible for Application Developers
  • Migrating Secrets Using HashiCorp Vault and Safe CLI
  • Debugging Deadlocks and Race Conditions
  • Using Unsupervised Learning to Combat Cyber Threats

Comments

Integration Partner Resources

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo