-
Create MongoDB Database with
bima_skeleton
as name -
Add
DB_DRIVER
,DB_HOST
,DB_PORT
,DB_NAME
,DB_USER
, andDB_PASSWORD
to.env
DB_DRIVER=mongo
DB_HOST=localhost
DB_PORT=27017
DB_NAME=bima_skeleton
DB_USER=root
DB_PASSWORD=aden
- Add MongoDB Repository and Paginator Adapter to
dics/containers.go
{
Name: "bima:repository:mongo",
Scope: bima.Application,
Build: (*repositories.MongoRepository)(nil),
},
{
Name: "bima:pagination:adapter:mongo",
Scope: bima.Application,
Build: func(
env *configs.Env,
dispatcher *events.Dispatcher,
) (*adapters.MongodbAdapter, error) {
return &adapters.MongodbAdapter{
Debug: env.Debug,
Dispatcher: dispatcher,
}, nil
},
Params: dingo.Params{
"0": dingo.Service("bima:config"),
"1": dingo.Service("bima:event:dispatcher"),
},
},
- Change
bima:handler
definition params to mongodb
{
Name: "bima:handler",
Scope: bima.Application,
Build: func(
env *configs.Env,
dispatcher *events.Dispatcher,
repository repositories.Repository,
adapter paginations.Adapter,
) (*handlers.Handler, error) {
return &handlers.Handler{
Debug: env.Debug,
Dispatcher: dispatcher,
Repository: repository,
Adapter: adapter,
}, nil
},
Params: dingo.Params{
"0": dingo.Service("bima:config"),
"1": dingo.Service("bima:event:dispatcher"),
"2": dingo.Service("bima:repository:mongo"),
"3": dingo.Service("bima:pagination:adapter:mongo"),
},
},
To use replica set, just put full dsn in DB_HOST
DB_DRIVER=mongo
DB_HOST=mongodb+srv://user:password@region.mongodb.net