Bootstrapping a database for testing

We will use the official Docker image to bootstrap a MongoDB instance. You can do it simply with the following command:

docker run -it --rm --name test-mongo -p 27017:27017 mongo

This command runs a container with the name test-mongo from the mongo image, and forwards the local port 27017 to the same internal port of the container. The data that container produces will be removed after container shutdown.

If you have a mongo client, you can use it to connect to an instance of database inside the container:

mongo 127.0.0.1:27017/admin

When you need to shut down the container, use the stop subcommand of docker and specify the name of the container:

docker stop test-mongo

It can also be terminated with Ctrl + C if you attached the container to a Terminal with -it arguments, as I did previously.

Now, we can look how to connect to a database using mongo and the r2d2-mongo crate.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.241.250