I recently discovered Anypoint Studio and the first question that came up to me was: how can I access my MongoDB cluster?
This is the fastest solution I have found :)
Create the Mule Project
Configure an HTTP Listener
With the sole purpose of being able to test our project later, I have added and configured an HTTP Listener:
Install and configure the MongoDB connector
- Open the Mule Palette view and select
Search in Exchange
. -
In the search box type "mongo" and search "MongoDB Connector" in the Available Modules tab. Then select it and click
add
andfinish
.
Make sure you choose the 6.3 version or higher.
Navigate to
Global Elements
tab.In the
General
tab select "Connection string" as connection option.
Some libraries must be installed. Just click
Configure...
>Add Recommended Libraries
Now we must include the connection string from our MongoDB atlas clusters.
Get your Connection String
- Go to your MongoDB Atlas project
Choose "Connect your application" and select
Java
as your application language (this is just for getting the connection string).Then copy the connection string and follow the MongoDB instructions (Replace password...)
[If you are having issues check the project allowed IPs and the database allowed users in your MongoDB settings]
Try it!
From the Mule pallete add
Create Collection
andInsert document
elements and select as Connector_Configuration the config we have just created.Configure both elements with the collection name and the document you want to insert...
Run the project, go to the HTTP listener url and then to your MongoDB collection list...
And that's all! I hope this information is useful for your projects :)
Top comments (0)