Note
This guide applies to Steeltoe v3. Please open an issue if you'd like to help update the content for Steeltoe v4.
Using Service Connectors with Mongo DB
This tutorial takes you through setting up a .NET Core application with the Mongo DB service connector.
Note
For more detailed examples, please refer to the MongoDb project in the Steeltoe Samples Repository.
First, start a Mongo DB instance. Depending on your hosting platform this is done in several ways.
Using the Steeltoe dockerfile, start a local instance of Mongo.
docker run --env MONGO_INITDB_ROOT_USERNAME=steeltoe --env MONGO_INITDB_ROOT_PASSWORD=Steeltoe234 --publish 27017:27017 mongo
Next, create a .NET Core WebAPI that interacts with Mongo DB
Create a new ASP.NET Core WebAPI app with the Steeltoe Initializr
Name the project "MongoConnector"
Add the "MongoDB" dependency
Click Generate to download a zip containing the new project
Extract the zipped project and open in your IDE of choice
Set the instance address in appsettings.json
{ "mongodb": { "client": { "server": "127.0.0.1", "port": "27017", "username": "steeltoe", "password": "Steeltoe234" } } }
Tip
Looking for additional params to use when connecting? Have a look at the docs
Run the application
dotnet run <PATH_TO>\MongoConnector.csproj
Navigate to the endpoint (you may need to change the port number) http://localhost:5000/api/values
Once the app loads in the browser you will see a list of the default databases installed with Mongo. "["admin","config","local"]"