0% found this document useful (0 votes)
164 views14 pages

Introduction to MongoDB and BSON

Mongo db

Uploaded by

Kp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
164 views14 pages

Introduction to MongoDB and BSON

Mongo db

Uploaded by

Kp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Introduction to

MongoDB
Agenda:

• What is MongoDB?
• What advantages does MongoDB have?
• Familiarization with BSON
• MongoDB data example and storing of data in JSON
• Installation of MongoDB Community Server
• Installation of MongoDB Compass
• How to create and drop DB?
• How to create and drop a Collection?
• MongoDB is a document-oriented NoSQL database
• Documents consist of key-value pairs
• MongoDB is a document-oriented NoSQL database management system (DBMS).
Unlike traditional relational DBMSs, which store data in tables consisting of rows and
columns, MongoDB stores data in JSON-like structures referred to as documents.

• Top NoSQL Document Databases. MongoDB, MarkLogic, InterSystems Caché,


OrientDB, Apache CouchDB, IBM Cloudant, CrateDB, Azure Cosmos DB, BaseX,
Couchbase Server, eXist DB, IBM Informix are some of the Top NoSQL Document
Databases.
• Support for all the popular languages like C, C++, C#, and .Net, Go, Java, [Link], Perl,
PHP, Python, Motor, Ruby, Scala, Swift, Mongoid.
SQL => Database -> table -> row and column(tuple and aliases)->data
MongoDb => Database -> collection -> documents -> record
JSON JavaScript objects are simple associative containers, wherein a string key is mapped to a value
(which can be a number, string, function, or even another object)
nested json structure
{
"_id": 1,// number
"name" : { "first" : "John", "last" : "Backus" }, // object
"contributors" : [ "Fortran", "ALGOL", "Backus-Naur Form", "FP" ], // array of string
"awardsDetails" : [ // array of object
{
"award" : "W.W. McDowell Award",
"year" : 1967,
"by" : "IEEE Computer Society"
}, {
"award" : "Draper Prize",
"year" : 1993,
"by" : "National Academy of Engineering"
}
]
}
Nornal json
{
“name”:”kush”,
“wakeUpTime”: “09:30”,
“yoga”: true,
“standupCall”:true,
“work”:{
“taska”:”done”,
“taskb”:”in progress”,
},
callAbhinav: function(){

},
activities:[“mobile-game”,”cricket-match”,”yoga”,”teaching”]

}, iTS NOT GOOD PRACTICE THAT VALUE TO BE function


React -> request data-> Nodejs -> SQL(table)
backend

backend
React -> request data-> Nodejs -> Mongodb(JSON)
BSON - Binary Javascript Object
Notation
• BSON was invented to bridge the gap:
• a binary representation to store data in JSON format,
• optimized for speed, space, and flexibility.
• BSON simply stands for “Binary JSON,”
• json data is in the from of human readable
• in bason data is in the form of machine redable
compare with table
awrad table => Big Difference
userId firstname lastname contribs award award_year award_by blocked
1 john backus Fortran fp Draper 1993 IEEE
2 abc xyz - - - - - - -- - - - - - - - -

MongoDb => write key everytime


{ …..},{userId:”1”,firstName”:”abac”,lastName”:”xyz”, blocked:”yes”}
ObjectId
• An ObjectId is a 12-byte BSON type having the following structure −

• The first 4 bytes representing the seconds since the unix epoch (timestamp)
(shows when it was created)
• The next 3 bytes are the machine identifier(shows about the machine)
• The next 2 bytes consists of process id(what’s the process is done by an user)
• The last 3 bytes are a random counter value
Some commands
show dbs; -> list down all the dbs
use ecommerce; <ecommerce> a db name; -> created
and switch to db

use for create or switch ;

[Link]("buyer"); ---> helps to create a new


collection

show collections; -> list down all the collections

[Link]({"name":"pooja",product:"tv"}) -> insrert


in to the collections

[Link](); -> show docuemnts list


MongoDB uses ObjectIds as the default value of _id field of each document,
which is generated while the creation of any document.
• download MongoDB
• [Link]
• [Link]

• [Link]
msi
• [Link]

• MongoDB Compass
• [Link]
• [Link]
Open mongo shell
• Connect URI
• mongodb://localhost:27017

You might also like