This guide provides a step-by-step introduction to using MongoDB Atlas, a cloud-based database platform for MongoDB deployment
Create a MongoDB Atlas Cluster
1 - Once logged in, navigate to the Clusters section in the MongoDB Atlas dashboard.
2 - Click on Create Cluster.
3 - Choose a Free Tier cluster (e.g., M0 Sandbox).
4 - Select a Cloud Provider (e.g., AWS, GCP) and a preferred Region (consider user location for optimal performance).
5 - Give your cluster a descriptive name (e.g., "My First Atlas Cluster").
6 - Click Create Cluster to initiate the deployment process.
Note: The cluster creation might take a few minutes.
Connect to Your Cluster
1 - In the Cluster view, navigate to the Connect tab.
2 - Choose a connection method that suits your development environment (e.g., Connection String).
3 - Copy the connection string and add it to MANGODB_URL
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 . 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.