ASP.NET Core sample app illustrating how to use the Steeltoe MongoDB Connector for connecting to a MongoDB database.
- Installed .NET 10 SDK
- Optional: Tanzu Platform for Cloud Foundry (optionally with Windows support) with Tanzu Cloud Service Broker for Microsoft Azure and Cloud Foundry CLI
- Optional: Tanzu Platform for Kubernetes v1.6 or higher and Tanzu CLI
- Start a MongoDB docker container
- Run the sample
dotnet run
Upon startup, the app inserts a couple of objects into the bound MongoDB database. They are displayed on the home page.
- Create a MongoDB service instance in an org/space
cf target -o your-org -s your-space cf marketplace cf marketplace -e your-offering cf create-service csb-azure-mongodb your-plan sampleMongoDbService --wait
- Run the
cf pushcommand to deploy from source (you can monitor logs withcf logs mongodb-connector-sample)- When deploying to Windows, binaries must be built locally before push. Use the following commands instead:
dotnet publish -r win-x64 --self-contained cf push -f manifest-windows.yml -p bin/Release/net10.0/win-x64/publish
- When deploying to Windows, binaries must be built locally before push. Use the following commands instead:
- Copy the value of
routesin the output and open in your browser
In order to connect to MongoDB for this sample, you must have a class claim available for the application to bind to.
The commands listed below will create the claim, and the claim will be bound to the application via the definition
in the workload.yaml that is included in the config folder of this project.
kubectl config set-context --current --namespace=your-namespace
tanzu service class-claim create sample-mongodb-service --class mongodb-unmanagedIf you'd like to learn more about these services, see claiming services and consuming services in the documentation.
To deploy from local source code:
tanzu app workload apply --local-path . --file ./config/workload.yaml -yAlternatively, from locally built binaries:
dotnet publish -r linux-x64 --no-self-contained
tanzu app workload apply --local-path ./bin/Release/net10.0/linux-x64/publish --file ./config/workload.yaml -ySee the Tanzu documentation for details.
See the Official Steeltoe Connectors Documentation for more detailed information.