-
Notifications
You must be signed in to change notification settings - Fork 73
MongoDB
The v2 starter kit now supports Postgres out of the box. However the same structure can also be used with other databases, for example MongoDB (via Mongoose).
PR#1767 shows what's needed, but it's basically a matter of:
-
Replacing
pg
(npm --workspace api uninstall pg
) withmongoose
(npm --workspace api install mongoose
)-
Update
api/utils/config.cjs
(to useMONGODB_URI
instead ofDATABASE_URL
, and strip out the unneeded Postgres configuration) andapi/server.js
accordingly -
Update
api/messages/messageRepository.js
to use a Mongoose model to access the collectionNote: this shows the benefit of having a repository abstraction layer;
messageRouter.js
andmessageService.js
don't have to change, even though we've swapped out the whole DB.
-
-
Replacing
node-pg-migrate
(npm --workspace api uninstall node-pg-migrate
) withmigrate-mongo
(npm --workspace api install migrate-mongo
)-
Use the ESM options, which also means you can migrate
api/utils/config.cjs
(CommonJS) ->api/utils/config.js
(ESM) -
Configuration moves from
api/migrations/config.cjs
toapi/migrate-mongo-config.js
-
Migration template moves from
api/migrations/template.cjs
toapi/migrations/sample-migration.js
-
Command in the
api/package.json
scripts changes to"migration": "migrate-mongo"
. -
New migrations can then be created in
api/migrations/
-
-
Updating the test setup in
api/setupTests.js
to start, connect to and migrate a MongoDB container instead of Postgres- Change the name of the env var set in the
api/package.json
'stest
script toMONGODB_URI
(the actual connection URI will be provided using the test container anyway)
- Change the name of the env var set in the
-
Updating workflows in
.github/workflows
to create a MongoDB instead of Postgres service container, and configure the env vars accordingly -
Updating
eslint.config.js
to correspond to the above changes