Database
Setup
-
Create a new project and deploy a cluster on MongoDB Atlas
💡Run a local database for your dev setup so you can work offline and it’s faster
-
In your project on MongoDB Altas, click [Network Access] then [+ Add IP Address]. Enter
0.0.0.0/0
in [Access List Entry]. This allows connections from your computer and your production deployment(s) (Vercel for instance). -
If you haven’t done it yet, rename
.env.example
to.env.local
. Then add your connection string toMONGODB_URI
in.env.local
.Mongoose (optional)
Mongoose makes it easier to deal with MongoDB and has some cool
features.
Models are defined in the folder/models
. Add any new models there. The plugin toJSON is added to all models to remove the_id
and_v
(easier on front-end).
Also if you addprivate: true
to any field it will be removed from the response. I.e. make email private so it’s not sent to the front-end.