1. Create Connection
1.1. Download MongoDB : apt-get install mongodb
1.2. Install MongoDB : npm install mongodb --save
1.3. start MongoDb services : service mongodb start
2. Create Database
var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/MongoDb";
MongoClient.connect(url, function(err, db) {
if (err) throw err;
console.log("Database created!");
db.close();
});
3. Create Collection
var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/ MongoDb";
MongoClient.connect(url, function(err, db) {
if (err) throw err;
db.createCollection("employees", function(err, res) {
if (err) throw err;
console.log("Collection is created!");
db.close();
});
});