FeaturesDatabase

Database

Setup

  1. 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


  2. 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).

  3. If you haven’t done it yet, rename .env.example to .env.local. Then add your connection string to MONGODB_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 add private: 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.