Skip to content

πŸš€ Setup

1️⃣ Create a new project and publish a cluster on MongoDB Atlas.


2️⃣ Run a local database for development setup:
- πŸ’» This allows you to work offline and speeds up development.


3️⃣ Inside your MongoDB Atlas project:
- 🌐 Click on [Network Access] then [+ Add IP Address].
- πŸ”‘ Enter: 0.0.0.0/0 in the [Access List Entry].
- 🌍 Why: This allows access from your machine and from deployed environments (like Vercel).


4️⃣ Environment variable setup:
- πŸ“ If you haven’t already, rename .env.example to .env.local.
- πŸ”— Then add your connection string to MONGODB_URI inside .env.local.


πŸ› οΈ Mongoose (Optional)

  • πŸ—ƒοΈ Why use Mongoose:
  • It simplifies working with MongoDB.
  • It offers helpful features out of the box.

  • πŸ“‚ Model organization:

  • Define your models inside the /models folder.
  • Add any new models there.

  • βœ… Frontend optimization:

  • The toJSON plugin has been added to all models to remove the _id and __v fields.
  • If you set private: true on any field, it will be excluded from the response.
  • For example, you can make the email field private so it won’t be sent to the frontend.