Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner (Part 5)

July 11, 2019

Hello! We already have created app.js file containing some important configurations for Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap. In this article we are going to create the model for the project. But first, we have to make the database in MongoDB Atlas.

Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner (Part 5)

What is MongoDB Atlas?

It is actually the same like the monogoDB that we install in our local computer. The difference is, if we want to deploy our web app in heroku or other free hosting website, then using MongoDB atlas is the best option as it's can be freely accessed online.

Make Database in MongoDB Atlas

Okay, let's follow this step together

2. Make account 
Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Creating Simple CRUD Using Node js, Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Express, Mongodb and Bootstrap For Beginner, Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Creating Simple CRUD Using Node js, Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Express, Mongodb and Bootstrap For Beginner
Make database with mongodb atlas | Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner 

3. Once you are done signing up (don’t forget to check your mail), then login
4. Klik Build New cluster
5. Choose the server and the tier. Do not forget to choose the “free tier available”
6. In the cluster tier, choose M0 to get free-forever database
7. click Create cluster

Great now you are done creating the cluster! And then wait until the cluster is ready.. The next step is to configure the database project.

Connect the database to our nodejs project.
1. Click connect -> click add your current IP address and set your mongodb user.
Don’t worry, I know that using postman must be so frustrating and of course, ‘not-user-fiendly enough’. I will also implement our own views here (using HTML).
2. Choose connect your application -> and copy the url
3. Ok from here, done. Now is the time to connect the database to the node project.
4. It is easy to connect it. We just change the value of MYCONNECTION in the .env file with the new url.

And the database configuration is now done. You can run your project to see whether the connection works correctly or not.
npm start

Create Model

If it works, then now we are going to make Model. In model, we are going to define the table (in mongodb called collection) and its attributes. 

1. In the project, we make a folder named models
2. Then we make a file called Notes.js . inside this file we can write these codes

//load mongoose module
const mongoose = require('mongoose');

//make the scheme of the collection
const NotesSchema = mongoose.Schema({
    title: String, //make an attribute title with type string
    content: String //make an attribute content with type stirng
});

//exports the module (collection scheme of mongodb)
module.exports = mongoose.model('Notes', NotesSchema); //'Notes' will be the name of collection and noteschema means the attributes that have been initialised above
Okay, I have explained the code using commands so I hope you guys can understand well :)

In the next step we will create the route for the middleware, test the APIs and create some simple interface using HTML,CSS-Bootstrap.

Table Content

title Link
Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap Part 1 Link
Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap Part 2 Link
Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap Part 3 Link
Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap Part 4 Link
Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap Part 5 Link
Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap Part 6 Link
Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap Part 7 Link

Tag : Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Creating Simple CRUD Using Node js, Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Express, Mongodb and Bootstrap For Beginner, Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner

Share this

Related Posts

Previous
Next Post »