Skip to main content

Mongoose for Beginner

iGyan.org Mongoose

Mongoose is object modeling tool for mongodb and node js. that means you can define your data model in your code it self not in database.

This is how the mongoose schema look like,
var UserSchema = new mongoose.Schema({
firstname:String,
lastname: String,
age: Number,
});

Mongoose allows you to define a schema of your data and use it in your code when you want.

Mongoose returns JSON object that you can use directly.

Installing Mongoose on the Ubuntu

Before you install mongoose on the machine we recommended you to install the prerequisites first.

Update the system

sudo apt-get update

NodeJS

sudo apt-get install nodejs

after installing nodejs you must check the version, it should be > v0.10.0
node --version

NPM

NPM is the package manager for Node, which is automatically installed when you install the nodejs. so you need to check the version of the NPM 
which should be > 0.6.3

npm --version

if it is not showing the version you can install it using the below command

sudo apt-get install npm

MongoDB

You can install mongodb using below command
sudo apt-get install mongodb
After installing mongodb you cnc check the status of the service using
sudo service mongodb status
If mongo db is not started then you can start it using
sudo service mongodb start
After the service is running in the background you can see the mongo shell on the terminal using 
mongo
It will show like below screenshot.

ExpressJs

We are going to install expressjs using the npm command
sudo npm install -g express
Here -g will install the express globally on your machine.

Mongoose

we can install mongoose using two ways.
1. Using npm install
sudo npm install mongoose
2. By adding dependency in package.json file. the file will be look like
{
"name": "iGyan Mangoose App",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node app"
},
"dependencies": {
"express": "3.0.0",
'mongoose': "3.6",
}
}

That we will use later on through out the Mongoose tutorial.



Popular posts from this blog

31 Most amaing fact about India

Here are some most amazing unknown facts about India from iGyan.Org that will blow your mind and you will be proud of it.

The name India is derived from Indus River, which originates from the Old Persian word Sindhi.India is the seventh largest country by area.India is the only country in the world which has both tigers and lions in the wild.New Delhi's air is the most polluted in the world.Indian Railways is the largest railway network in the world under single management.Other than US and Japan, India is the only country to have built a super computer indigenously. India is ranked the sixth country in the world in terms of satellite launches.The world's first university was established in Takshashila in 700 BC.Ayurveda of India is the earliest school of medicine known to the world.Four out of 10 Silicon Valley startups are run by Indians.India is the world's premier center for diamond cutting and polishing. Nine out of every 10 stones sold in the world pass through India…

Interesting facts about Indian currency symbol

Here are some interesting fact about the Indian currency symbol. Indian Currency Symbol has been presented publiclly by the goverment of india on 15th july 2010.The symbol uses U+20B9 unicode charactar.Indian currency symbol was designed by Udaya Kumar.

Top Inspiring Quotes From Albert Einstein

Most Beautifully said Top Inspiring Quotes By Albert Einstein, A Huge leftest collection of Einstein Quotes.