Introduction Of MongoDB And Environment Setup Of MongoDB


Mongo DB is a cross-platform, open-source document-oriented database. Mongod is a NoSQL database (no structure). Mongo DB stores JSON data in the form of collections. MongoDB has no structure of the data so it’s called NoSQL data. Mongo DB has no limit to store collection and documents to the database like SQL. Mongo DB also has no required declared length of the field like SQL / Oracle / SqlYog.
If you create a database and define4 fields (id, name, salary, mobile) in your collection document, if you want to add more the 6 fields in the collection document, then you don’t need to define all fields in the collection. You directly add all fields to your collection. MongoDB database automatic adds extra fields with all values which you define in the query. This query is applied for all data in the collection. It will take null value for added extra fields.

Functions of Mongo DB

The functions of MongoDB are create, insert ,delete,update, read operation,
Insert one functions are use to insert a record in database at a time. If you want to insert a record in a database then you need to use insertOne().
  1. var customer = {_id:111, name:"Santosh Kumar" , address: "B-222, Sector-19, NOIDA", orderdata:"Arrow Shirt"};    
  2. mersCollection.insertOne(customer, function(error, response) { }     
InsertMany() functions are use to store a number of records in a collection.
  1. var customers = [    
  2.      {name:"Rakesh Kumar" , address: "B-222, Sector-12, NOIDA", orderdata:"TV"},    
  3.        {name:"Amit Kumar" , address: "C-222, Sector-22, NOIDA", orderdata:"Sofa set"},    
  4.        {name:"Kamesh Kumar" , address: "D-222, Sector-32, NOIDA", orderdata:"Dinig table"},    
  5.        {name:"Deleep Kumar" , address: "E-222, Sector-42, NOIDA", orderdata:"jeans"}    
  6.   ];    
  7.  nodeDB.collection("customers").insertMany(customers, function(error, response) }    
DeleteOne() functions are use to delete one record from the collection.
  1. var deleteQuery = { username:"croma campus"};    
  2.   nodeDB.collection("customers").deleteOne(deleteQuery, function(err, response) {    
  3.     if (err) throw err;    
  4.     console.log(response.result.n + " document deleted");    
  5.   });    
DeleteMany() are use to delete one multiple record from collection.
  1. var deleteQuery = {};    
  2.  nodeDB.collection("customers").deleteMany(deleteQuery, function(err, obj) { }     
findOne() are use to find one record from collection.
  1. nodeDB.collection("users").findOne({price:4.5}, function(err, result) {    
  2.             if (err) throw err;    
  3.             console.log( + ", " + result.address + ", " + result.orderdata);    
  4.       });      
findMany() are use to find many record from collection
  1. nodeDB.collection("customers").find({}).toArray(function(err, totalCustomers) {    
  2.         if (err) throw err;    
  4.         for(i = 0; i < totalCustomers.length; i++) {    
  5.              let customer = totalCustomers[i];    
  6.            console.log( + ", " + customer.address + ", " + customer.orderdata);  
  7. }    
updateOne() are use to update one record from collection.
  1. var whereClause = { address: "B-222, Sector-12, NOIDA" };    
  2.   var newvalues = {$set: { address: "B-44444444, Sector-12, NOIDA" }};    
  3.   nodeDB.collection("customers").updateOne(whereClause, newvalues, function(err, res) {    
  4.     if (err) throw err;    
  5.     console.log(res.result.n + " document updated");      
  6. });     
update many function are use to update many record from collection.
  1. var newvalues = {$set: {name: "Mukesh"} };    
  2.   nodeDB.collection("customers").updateMany(myquery, newvalues, function(err, res) {    
  3.     if (err) throw err;    
  4.     console.log(res.result.nModified + " document(s) updated");    
  5.     databases.close();    
  6.   });    
  7.   });      

Different between SQL and MongoDB 

 SQL Database  Mongo DB Database
 Sql store record in the table  Mongo db store data in collection
 Data manage in row and column and each row represent a option in oops  Data manage in the form of JSon
 Predefine nature  Nature is not define (no nature)
 Record created  Document created
 Insert into table  Insert into Json
Select*from table use to display table  Db.collection.find use to find document

Advantages of MongoDB

  • MongoDB is a document database in which one collection has many documents, field sizes, and content.
  • No complex of join
  • Mongodb is easy to scale
  • No need for mapping/conversion
  • Data stored in the form of JSON style
  • Store big data
  • Fast in-place update

How to download MongoDB compass

Open your browser and search on the browser Download mongodb compass. You can download it directly from the link.
Afterward, download your Mongo DB open .exe file and install. After completion, go to the web services and start mongodb service.
then go to "C:MongoDB\bin\mongod.exe" ---- config "C:\MongoDB\mongod.cfg" --- install then go to the cmd and run command on cmd,
  1. install mongodb --save  
After a few minutes, all mongodb packages should be completely installed. Now MongoDB is installed in your system.

Similar Articles