This demo aims to introduce the MongoDB connector to users and how one is able to execute a simple CRUD workflow against a MongoDB collection. This demo is composed of four steps: - The "Create" step is used to add a record to a collection. - The "Read" step is used to query a single record where the "message" field is equal to the one specified in the HTML form. - The "Update" step is used to update the record found in the second step with a new message. - The "Delete" step is used to delete the record that was created in the first step, thereby leaving the collection in the database in the same state it initially started with.
You are able to extend this demo by adding a 5th step that deletes the Mongo collection which contains the entries created in this demo.
This demo makes use of a number of property placeholders which can be found in src/main/resources/demo-app.properties. The description for each property is outlined below:
Property | Description |
---|---|
mongo.host |
Specifies the host at which the MongoDB instance is located |
mongo.port |
Specifies the port on which the MongoDB instance is listening on |
mongo.username |
Specifies the username that Mule should use to connect to the MongoDB instance |
mongo.password |
Specifies the password that Mule should use to connect to the MongoDB instance |
mongo.database |
Specifies which database Mule should use to create MongoDB collections |
mongo.defaultCollection |
Every single workflow step will execute against this collection |
This demo makes use of 5 endpoints:
Endpoint | Description |
---|---|
This endpoint provides you with a form that sends requests to the following URLs. |
|
This endpoint exposes the first step in the workflow. This is used to add an entry to MongoDB with the specified values in the form. |
|
This endpoint exposes the second step in the workflow. It is used to read a value from Mongo based on the values defined in the form. |
|
This is the third step in the workflow and it is used to update an existing record in the Mongo collection |
|
This is the fourth and final step in the workflow. It is used to delete an existing record in a Mongo collection when given a Mongo Object ID. |
To run this demo, import this Mule project in Anypoint Studio by clicking on File > Import and select Anypoint Studio Project from External Location. Once your project is imported, open "demo-app.properties" under the src/main/resources folder and fill in all the properties. Once you have configured these properties, right click on its name in the Project Explorer view and click on Run As > Mule Application. If you’ve configured everything correctly, your application should start. Navigate to http://localhost:8081 and initiate the workflow by using the form.