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/0in [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.exampleto.env.local. Then add your connection string toMONGODB_URIin.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_idand_v(easier on front-end).
Also if you addprivate: trueto any field it will be removed from the response. I.e. make email private so it’s not sent to the front-end.