Configure the MongoDB component in Mule Flow.
Execute the flow to save a document.
Execute the flow to retrieve the document saved.
Install the MongoDB that your OS supports.
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
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:
Configure the MongoDB component as below.
Provide username, password, database name, and HOST & PORT details.
Configure the properties of the MongoDB component as follows.
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.
Execute the Flow to Retrieve the Saved Document
To query MongoDB for documents, use the "Find One Document" operation. The flow is as follows:
The MongoDB configuration details for the retrieval of the document are as follows:
Query MongoDB through the Postman client as below; the query hits the MongoDB component in the Mule flow:
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.
The MongoDB connector has the capability to store and retrieve documents from the Mule flow efficiently and with minimal configuration.