A MERN simple REST API template using MongoDb on Atlas free server and MongoDb extension on Visual Studio Code
Based on Mongodb tutorial How to Use MERN Stack: A Complete Guide.
- npm version ^16
- Visual Studio Code
-
Clone this repo
-
You can follow the Getting Started with Atlas guide, to learn how to create a free Atlas account, create your first cluster and get your Connection String to the database. Then, set the Atlas URI connection parameter in
server/.env
to your Connection String:
ATLAS_URI=mongodb+srv://<username>:<password>@sandbox.jadwj.mongodb.net/myFirstDatabase?retryWrites=true&w=majority
- Start the Express server:
cd server
npm install
npm install -g nodemon
nodemon server
you should see a "Successfully connected to MongoDB" message on terminal, let it running
- Start the React app: open another Terminal tab
cd client
npm install
npm start
-
Test App on localhost:3000 Create a Record Edit that record
-
Install Visual Studio Code and MongoDB extension https://code.visualstudio.com/docs/azure/mongodb
- Use the same connecting string contained in .env file to connect to Atlas MongoDb using the VS code MongoDb extension
- Open MERNtutorial_employee_populate.mongodb and press 'Play' button
-
Check out new records inserted on both Atlas UI and localhost
- Go to https://cloud.mongodb.com/ navigate to collections > MERNstackDB > employee and check new records just inserted
- Refresh your localhost:3000 on browser and check if the new records are there
-
You can also execute the other mongoDb files to get used to mongodb shell sintax for insert, erase, update and delete data on mongodb:
- open server/db/MERNtutorial_* files and execute them
Use at your own risk; not a supported MongoDB product