Deploying a MongoDB cluster in Testcontainers
MongoDB transactions are only supported in multiple server clusters. However, MongoDBContainer
, as explained in the Using Testcontainers with MongoDB recipe uses a single server deployment. Therefore, we cannot use it for the integration tests of the new feature to buy cards as it requires transactions.
In this recipe, we’ll learn how to set up multiple Testcontainers and configure a MongoDB cluster. With that, we’ll be able to implement integration tests for the buy cards feature.
Getting ready
This recipe will implement the integration tests for the Using transactions in MongoDB recipe. If you haven’t completed it yet, don’t worry – I’ve prepared a version from which you can start this recipe. You can find it in this book’s GitHub repository at https://github.com/PacktPublishing/Spring-Boot-3.0-Cookbook, in chapter6/recipe6-5/start
.
How to do it...
In this recipe, we’...