Description
Nest based example of API. Uses Mongo DB in replica set mode from Docker Compose. It's an example just for development.
Ports in use: 9000, 9001, 27048.
Port 9000: gateway microservice.
Port 9001: users microservice.
Port 27048: Mongo DB in Docker in replica set mode.
How to run
First of all, in directories gateway
and users
rename files .env.example
to .env
.
Gateway microservice:
# gateway
$ cd gateway
$ npm install
$ npm run start:dev
Users microservice:
# users
$ cd users
$ npm install
$ npm run generate:key
$ npm run db:up
$ npm run rs:init
$ npm run start:dev
Postman calls
Upload file ./nest_mongo_rs.postman_collection.json
from the root directory of the repo to your local Postman. Then run calls sequentially: Post Create User, Get User By Id, Post Create Group. The last one uses Mongo transactions. Its successful execution is a signal that Mongo is running in replica set mode locally, in Docker Compose.
Mongo DSN
To have a look on Mongo DB collections:
mongodb://dotcommando:dotcommando@localhost:27048/ms-users?authSource=admin&replicaSet=rs0
Commands in Users microservice
Before the first run of replica set you should generate a key:
$ npm run generate:key
After key generation up the Docker Compose with Mongo in replica set mode:
$ npm run db:up
You can stop this service:
$ npm run db:stop
Or fully remove:
$ npm run db:rm
After you run DB with command npm run db:up
you should initialize replica set mode:
$ npm run rs:init
To check if replica set is OK:
$ npm run rs:conf
License
The boilerplate is MIT licensed.
Author: Mikhail Filchushkin.