Step 1
Install mongo db using following command
npm install mongodb --save
Step 2
Create the following folder
C:\data\db
step 3
cd
toC:\Program Files\MongoDB\Server\3.2\bin
- enter command
mongod
- by default, mongodb server will start at port
27017
setp 4
Write following code and run nodejs application using visual studio IDE
var MongoClient = require('mongodb').MongoClient;
// Connect to the db
MongoClient.connect("mongodb://localhost:27017/MyDb", function (err, db) {
if(err) throw err;
//Write databse Insert/Update/Query code here..
});
step 5
perform Insert operation using below code
var MongoClient = require('mongodb').MongoClient;
// Connect to the db
MongoClient.connect("mongodb://localhost:27017/db", function (err, db) {
db.collection('TestData', function (err, collection) {
collection.insert({ id: 1, firstName: 'Test', lastName: 'Test11' });
collection.insert({ id: 2, firstName: 'Test1', lastName: 'Test12' });
collection.insert({ id: 3, firstName: 'Test2', lastName: 'Test21' });
db.collection('TestData').count(function (err, count) {
if (err) throw err;
console.log('Total Rows: ' + count);
});
});
});
Hello Vinod,
ReplyDeleteThanks for the information about Connecting MongoDB/., Its been always a headache to do that in Microsoft Dot Net
Well explained about the issue,,Solved my problem. Thanks for it!! I hope a professional Microsoft Dot Net Training will give a clear idea in solving the issues.
ReplyDeleteThank for sharing Awesome blog with us.
ReplyDeleteFull Stack Training in Hyderabad
Full Stack Training in Ameerpet
Thank You so much for your effort in sharing such a wonderful blog with usGood information. Thanks for sharing with us
ReplyDeleteoracle training in chennai
oracle training institute in chennai
oracle training in bangalore
oracle training in hyderabad
oracle training
hadoop training in chennai
hadoop training in bangalore
etiler
ReplyDeletegümüşhane
siirt
üsküdar
karabük
ON1