Getting started
As a first step, we need to install the Mongoose npm package, as well as the Nest.js/Mongoose npm package.
Run npm install --save mongoose @nestjs/mongoose
in your console, and npm install --save-dev @types/mongoose
inmediately after.
Set up the database
Docker Compose is the easiest way to get started with MongoDB. There’s an official MongoDB image in the Docker registry we recommend that you use. The latest stable version at the moment of writing this is 3.6.4
.
Let’s create a Docker Compose file to build and start both the database we will be using, as well as our Nest.js app, and link them together so that we can access the database later from our code.
version
:
'3'
volumes
:
mongo_data
:
services
:
mongo
:
image
:
mongo
:
latest
ports
:
-
"27017:27017"
volumes
:
-
mongo_data
:
/data/db
api
:
build
:
context
:
.
dockerfile
:
Dockerfile
args
:
-
NODE_ENV
=
development
depends_on
:
...