SlideShare a Scribd company logo
1 of 32
MONGODB
DATABASES
Create database
DATABASE->COLLECTIONS->DOCUMENTS
There is no create database command in MongoDB. Actually, MongoDB do not provide any
command to create database.
It may be look like a weird concept, if you are from traditional SQL background where you need
to create a database, table and insert values in the table manually.
Here, in MongoDB you don't need to create a database manually because MongoDB will create
it automatically when you save the value into the defined collection at first time.
Syntax:
useDATABASE_NAME
EX:
>usemydb
switchedtodb mydb
>db
mydb
Showdbs
Local0.000GB
Here, your created database “mydb" is not present in the list, insert at least one document into
it to display database:
>db.mycollections.insert({"name":“me"})
WriteResult({ "nInserted": 1})
>show dbs
mydb 0.078GB
local 0.078GB
In MongoDB, db.collection.drop() method is used to drop a collection from a database. It
completely removes a collection from the database and does not leave any indexes associated
with the dropped collections.
The db.collection.drop() method does not take any argument and produce an error when it is
called with an argument. This method removes all the indexes associated with the dropped
collection.
Syntax:
db.COLLECTION_NAME.drop()
First check the already existing collections in your database.
>use mydb
Switched to db mydb
> show collections
SSSIT
system.indexes
db.dropDatabase()
Dropped mydb
>db.SSSIT.drop()
>show collections
System.indexes
Create collection and drop collection
 CREATE COLLECTION
db.createCollection(“mycollection”)
show collections
mycollection
db.mycollection2.insert({“name”:”max”})
 DROP COLLECTION
db.mycollection.drop()
CRUD
MongoDB insert documents
In MongoDB, the db.collection.insert() method is used to add or insert new documents into a
collection in your database.
Syntax
>db.COLLECTION_NAME.insert(document)
db.school.insert(
{
“Studentno”:”1”,
“Studentname”:”mark”
},
)
WriteResult({ "nInserted" : 1 })
db.school.insert(
[ {
“Studentno”:”1”,
“Studentname”:”mark”
},
{
“Studentno”:”2”,
“Studentname”:”max”
}
)
WriteResult({ "nInserted" : 2 })
Query document
use school
db.students.find()
{ "_id" : ObjectId(5983548781331adf45ec5), “1":“mark"}
{ "_id" : ObjectId(5983548781331adf45ec6), “2":“max"}
* all data
db.students.find().pretty()
*Object id,studentno student name
db.students.findone()
* gives first document
db.students.find(“studentno”:”1”)
*returns student 1 document
db.student.find(“age”:{$gt :”15”})
* returns age greater than 15
db.student.find(“age”:{$gte :”15”})
* returns age greater than equal to 15
MongoDB - Update Document
MongoDB's update() and save() methods are used to update document into a collection. The
update() method updates the values in the existing document while the save() method replaces
the existing document with the document passed in save() method.
MongoDB Update() Method
The update() method updates the values in the existing document.
Syntax
The basic syntax of update() method is as follows −
>db.COLLECTION_NAME.update(SELECTION_CRITERIA, UPDATED_DATA)
{ "_id" : ObjectId(5983548781331adf45ec5), "title":"MongoDB Overview"}
{ "_id" : ObjectId(5983548781331adf45ec6), "title":"NoSQL Overview"}
{ "_id" : ObjectId(5983548781331adf45ec7), "title":"Tutorials Point Overview"}
>db.mycol.update({'title':'MongoDB Overview'},{$set:{'title':'New MongoDB Tutorial'}})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
>db.mycol.find()
{ "_id" : ObjectId(5983548781331adf45ec5), "title":"New MongoDB Tutorial"}
{ "_id" : ObjectId(5983548781331adf45ec6), "title":"NoSQL Overview"}
{ "_id" : ObjectId(5983548781331adf45ec7), "title":"Tutorials Point Overview"}
By default, MongoDB will update only a single document. To update multiple documents, you
need to set a parameter 'multi' to true.
>db.mycol.update({'title':'MongoDB Overview'},
{$set:{'title':'New MongoDB Tutorial'}},{multi:true})
MongoDB Save() Method
The save() method replaces the existing document with the new document passed in the save()
method.
Syntax
The basic syntax of MongoDB save() method is shown below −
>db.COLLECTION_NAME.save({_id:ObjectId(),NEW_DATA})
MongoDB - Delete Document
The remove() Method
MongoDB's remove() method is used to remove a document from the collection.
remove() method accepts two parameters.
One is deletion criteria and second is justOne flag.
deletion criteria − (Optional) deletion criteria according to documents will be removed.
justOne − (Optional) if set to true or 1, then remove only one document.
Syntax
Basic syntax of remove() method is as follows −
>db.COLLECTION_NAME.remove(DELLETION_CRITTERIA)
Example
Consider the mycol collection has the following data.
{_id : ObjectId("507f191e810c19729de860e1"), title: "MongoDB Overview"},
{_id : ObjectId("507f191e810c19729de860e2"), title: "NoSQL Overview"},
{_id : ObjectId("507f191e810c19729de860e3"), title: "Tutorials Point Overview"}
>db.mycol.remove({'title':'MongoDB Overview'})
WriteResult({"nRemoved" : 1})
> db.mycol.find()
{"_id" : ObjectId("507f191e810c19729de860e2"), "title" : "NoSQL Overview" }
{"_id" : ObjectId("507f191e810c19729de860e3"), "title" : "Tutorials Point Overview" }
Remove Only One
If there are multiple records and you want to delete only the first record, then set justOne
parameter in remove() method.
>db.COLLECTION_NAME.remove(DELETION_CRITERIA,1)
Remove All Documents
If you don't specify deletion criteria, then MongoDB will delete whole documents from the
collection. This is equivalent of SQL's truncate command.
> db.mycol.remove({})
WriteResult({ "nRemoved" : 2 })
> db.mycol.find()
>
Cassandra
Apache Cassandra is an open source, distributed and decentralized/distributed storage
system (database), for managing very large amounts of structured data spread out across the
world.
It provides highly available service with no single point of failure.
It is scalable, fault-tolerant, and consistent.
Apache Cassandra is a highly scalable, high-performance distributed database designed to
handle large amounts of data across many commodity servers, providing high availability with
no single point of failure.
It is a type of NoSQL database.
Features of Cassandra
Cassandra has become so popular because of its outstanding technical features. Given below are some of the features of
Cassandra:
Elastic scalability − Cassandra is highly scalable; it allows to add more hardware to accommodate more customers and
more data as per requirement.
Always on architecture − Cassandra has no single point of failure and it is continuously available for business-critical
applications that cannot afford a failure.
Fast linear-scale performance − Cassandra is linearly scalable, i.e., it increases your throughput as you increase the
number of nodes in the cluster. Therefore it maintains a quick response time.
Flexible data storage − Cassandra accommodates all possible data formats including: structured, semi-structured, and
unstructured. It can dynamically accommodate changes to your data structures according to your need.
Easy data distribution − Cassandra provides the flexibility to distribute data where you need by replicating data across
multiple data centers.
Transaction support − Cassandra supports properties like Atomicity, Consistency, Isolation, and Durability (ACID).
Fast writes − Cassandra was designed to run on cheap commodity hardware. It performs blazingly fast writes and can
store hundreds of terabytes of data, without sacrificing the read efficiency.
History of Cassandra
Cassandra was developed at Facebook for inbox search.
It was open-sourced by Facebook in July 2008.
Cassandra was accepted into Apache Incubator in March 2009.
It was made an Apache top-level project since February 2010.
Hbase
HBase is a data model that is similar to Google’s big table designed to provide quick random
access to huge amounts of structured data.
TheCAPtheorem,originallyintroducedastheCAPprinciple,canbeusedto explainsomeofthecompetingrequirementsina
distributed systemwithreplication.Itisa toolusedto makesystemdesignersaware ofthetrade-offswhiledesigningnetworked
trade-offswhiledesigningnetworkedshared-data systems.
ThethreelettersinCAPreferto threedesirableproperties ofdistributed systemswith replicateddata: consistency(among
Consistency–
Consistencymeansthat thenodeswillhavethesamecopiesofa replicateddata itemvisibleforvarious transactions.A
various transactions. Aguaranteethateverynodeina distributed clusterreturnsthesame,mostrecent,successfulwrite.
recent,successfulwrite.Consistencyreferstoeveryclienthavingthesameviewofthedata. Therearevarious typesof
Therearevarious types ofconsistencymodels.ConsistencyinCAPrefersto sequentialconsistency,averystrongformof
consistency,a verystrongformofconsistency.
Availability –
Availability meansthat eachreadorwriterequestforadata itemwilleitherbeprocessedsuccessfullyorwillreceiveamessage
successfullyorwillreceivea messagethat theoperation cannotbecompleted.Everynon-failingnodereturnsaresponseforall
nodereturnsaresponseforallreadandwrite requestsina reasonableamount oftime.Thekeyword hereis every.Tobe
wordhereisevery.Tobeavailable,everynodeon(eithersideofanetworkpartition) mustbeableto respondinareasonable
ableto respondinareasonableamount oftime.
Partition Tolerant–
Partition tolerancemeansthat thesystem cancontinueoperatingifthenetworkconnectingthenodeshasa faultthat results in
nodeshasafaultthatresultsin two ormorepartitions, wherethenodesineachpartition canonlycommunicateamong each
onlycommunicateamongeachother.Thatmeans,thesystemcontinuesto functionandupholds its consistencyguarantees in
upholdsitsconsistencyguaranteesinspiteofnetworkpartitions. Networkpartitions areafactoflife.Distributed systems
oflife.Distributed systemsguaranteeingpartition tolerancecangracefullyrecoverfrompartitions oncethepartition heals.
partitions oncethepartition heals.

More Related Content

Similar to 171_74_216_Module_5-Non_relational_database_-mongodb.pptx

Introduction to Apache Tajo: Data Warehouse for Big Data
Introduction to Apache Tajo: Data Warehouse for Big DataIntroduction to Apache Tajo: Data Warehouse for Big Data
Introduction to Apache Tajo: Data Warehouse for Big DataGruter
 
Building Hybrid data cluster using PostgreSQL and MongoDB
Building Hybrid data cluster using PostgreSQL and MongoDBBuilding Hybrid data cluster using PostgreSQL and MongoDB
Building Hybrid data cluster using PostgreSQL and MongoDBAshnikbiz
 
Introduction To MongoDB
Introduction To MongoDBIntroduction To MongoDB
Introduction To MongoDBElieHannouch
 
Overview on NoSQL and MongoDB
Overview on NoSQL and MongoDBOverview on NoSQL and MongoDB
Overview on NoSQL and MongoDBharithakannan
 
MongoDB using Grails plugin by puneet behl
MongoDB using Grails plugin by puneet behlMongoDB using Grails plugin by puneet behl
MongoDB using Grails plugin by puneet behlTO THE NEW | Technology
 
MongoDB Knowledge share
MongoDB Knowledge shareMongoDB Knowledge share
MongoDB Knowledge shareMr Kyaing
 
introtomongodb
introtomongodbintrotomongodb
introtomongodbsaikiran
 
Graph db as metastore
Graph db as metastoreGraph db as metastore
Graph db as metastoreHaris Khan
 
Starting with MongoDB
Starting with MongoDBStarting with MongoDB
Starting with MongoDBDoThinger
 
MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)Uwe Printz
 
MongoDB installation,CRUD operation & JavaScript shell
MongoDB installation,CRUD operation & JavaScript shellMongoDB installation,CRUD operation & JavaScript shell
MongoDB installation,CRUD operation & JavaScript shellShahDhruv21
 
Entity Framework Database and Code First
Entity Framework Database and Code FirstEntity Framework Database and Code First
Entity Framework Database and Code FirstJames Johnson
 
MongoDB NoSQL database a deep dive -MyWhitePaper
MongoDB  NoSQL database a deep dive -MyWhitePaperMongoDB  NoSQL database a deep dive -MyWhitePaper
MongoDB NoSQL database a deep dive -MyWhitePaperRajesh Kumar
 
An Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDBAn Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDBLee Theobald
 

Similar to 171_74_216_Module_5-Non_relational_database_-mongodb.pptx (20)

Introduction to Apache Tajo: Data Warehouse for Big Data
Introduction to Apache Tajo: Data Warehouse for Big DataIntroduction to Apache Tajo: Data Warehouse for Big Data
Introduction to Apache Tajo: Data Warehouse for Big Data
 
MongoDB
MongoDBMongoDB
MongoDB
 
MongoDB_ppt.pptx
MongoDB_ppt.pptxMongoDB_ppt.pptx
MongoDB_ppt.pptx
 
Building Hybrid data cluster using PostgreSQL and MongoDB
Building Hybrid data cluster using PostgreSQL and MongoDBBuilding Hybrid data cluster using PostgreSQL and MongoDB
Building Hybrid data cluster using PostgreSQL and MongoDB
 
Introduction To MongoDB
Introduction To MongoDBIntroduction To MongoDB
Introduction To MongoDB
 
Overview on NoSQL and MongoDB
Overview on NoSQL and MongoDBOverview on NoSQL and MongoDB
Overview on NoSQL and MongoDB
 
MongoDB using Grails plugin by puneet behl
MongoDB using Grails plugin by puneet behlMongoDB using Grails plugin by puneet behl
MongoDB using Grails plugin by puneet behl
 
MongoDB Knowledge share
MongoDB Knowledge shareMongoDB Knowledge share
MongoDB Knowledge share
 
Mongo db
Mongo dbMongo db
Mongo db
 
introtomongodb
introtomongodbintrotomongodb
introtomongodb
 
Graph db as metastore
Graph db as metastoreGraph db as metastore
Graph db as metastore
 
The emerging world of mongo db csp
The emerging world of mongo db   cspThe emerging world of mongo db   csp
The emerging world of mongo db csp
 
Starting with MongoDB
Starting with MongoDBStarting with MongoDB
Starting with MongoDB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)
 
MongoDB installation,CRUD operation & JavaScript shell
MongoDB installation,CRUD operation & JavaScript shellMongoDB installation,CRUD operation & JavaScript shell
MongoDB installation,CRUD operation & JavaScript shell
 
La sql
La sqlLa sql
La sql
 
Entity Framework Database and Code First
Entity Framework Database and Code FirstEntity Framework Database and Code First
Entity Framework Database and Code First
 
MongoDB NoSQL database a deep dive -MyWhitePaper
MongoDB  NoSQL database a deep dive -MyWhitePaperMongoDB  NoSQL database a deep dive -MyWhitePaper
MongoDB NoSQL database a deep dive -MyWhitePaper
 
An Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDBAn Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDB
 

Recently uploaded

Determinants of health, dimensions of health, positive health and spectrum of...
Determinants of health, dimensions of health, positive health and spectrum of...Determinants of health, dimensions of health, positive health and spectrum of...
Determinants of health, dimensions of health, positive health and spectrum of...shambhavirathore45
 
Edukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxEdukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxolyaivanovalion
 
FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfMarinCaroMartnezBerg
 
ALSO dropshipping via API with DroFx.pptx
ALSO dropshipping via API with DroFx.pptxALSO dropshipping via API with DroFx.pptx
ALSO dropshipping via API with DroFx.pptxolyaivanovalion
 
{Pooja: 9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
{Pooja:  9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...{Pooja:  9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
{Pooja: 9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...Pooja Nehwal
 
CebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxCebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxolyaivanovalion
 
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% SecureCall me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% SecurePooja Nehwal
 
VidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptxVidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptxolyaivanovalion
 
Halmar dropshipping via API with DroFx
Halmar  dropshipping  via API with DroFxHalmar  dropshipping  via API with DroFx
Halmar dropshipping via API with DroFxolyaivanovalion
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfRachmat Ramadhan H
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz1
 
Week-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionWeek-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionfulawalesam
 
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...shivangimorya083
 
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...amitlee9823
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxolyaivanovalion
 
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
Accredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdfAccredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdfadriantubila
 

Recently uploaded (20)

Determinants of health, dimensions of health, positive health and spectrum of...
Determinants of health, dimensions of health, positive health and spectrum of...Determinants of health, dimensions of health, positive health and spectrum of...
Determinants of health, dimensions of health, positive health and spectrum of...
 
Edukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxEdukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFx
 
FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdf
 
Sampling (random) method and Non random.ppt
Sampling (random) method and Non random.pptSampling (random) method and Non random.ppt
Sampling (random) method and Non random.ppt
 
ALSO dropshipping via API with DroFx.pptx
ALSO dropshipping via API with DroFx.pptxALSO dropshipping via API with DroFx.pptx
ALSO dropshipping via API with DroFx.pptx
 
{Pooja: 9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
{Pooja:  9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...{Pooja:  9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
{Pooja: 9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
 
CebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxCebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptx
 
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% SecureCall me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
 
VidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptxVidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptx
 
Halmar dropshipping via API with DroFx
Halmar  dropshipping  via API with DroFxHalmar  dropshipping  via API with DroFx
Halmar dropshipping via API with DroFx
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signals
 
Week-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionWeek-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interaction
 
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
 
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptx
 
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
Accredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdfAccredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdf
 
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
 

171_74_216_Module_5-Non_relational_database_-mongodb.pptx

  • 3. There is no create database command in MongoDB. Actually, MongoDB do not provide any command to create database. It may be look like a weird concept, if you are from traditional SQL background where you need to create a database, table and insert values in the table manually. Here, in MongoDB you don't need to create a database manually because MongoDB will create it automatically when you save the value into the defined collection at first time.
  • 5. Here, your created database “mydb" is not present in the list, insert at least one document into it to display database: >db.mycollections.insert({"name":“me"}) WriteResult({ "nInserted": 1}) >show dbs mydb 0.078GB local 0.078GB
  • 6. In MongoDB, db.collection.drop() method is used to drop a collection from a database. It completely removes a collection from the database and does not leave any indexes associated with the dropped collections. The db.collection.drop() method does not take any argument and produce an error when it is called with an argument. This method removes all the indexes associated with the dropped collection. Syntax: db.COLLECTION_NAME.drop()
  • 7. First check the already existing collections in your database. >use mydb Switched to db mydb > show collections SSSIT system.indexes db.dropDatabase() Dropped mydb
  • 9. Create collection and drop collection  CREATE COLLECTION db.createCollection(“mycollection”) show collections mycollection db.mycollection2.insert({“name”:”max”})  DROP COLLECTION db.mycollection.drop()
  • 10. CRUD
  • 11. MongoDB insert documents In MongoDB, the db.collection.insert() method is used to add or insert new documents into a collection in your database. Syntax >db.COLLECTION_NAME.insert(document)
  • 14. Query document use school db.students.find() { "_id" : ObjectId(5983548781331adf45ec5), “1":“mark"} { "_id" : ObjectId(5983548781331adf45ec6), “2":“max"} * all data db.students.find().pretty() *Object id,studentno student name
  • 15. db.students.findone() * gives first document db.students.find(“studentno”:”1”) *returns student 1 document db.student.find(“age”:{$gt :”15”}) * returns age greater than 15 db.student.find(“age”:{$gte :”15”}) * returns age greater than equal to 15
  • 16. MongoDB - Update Document
  • 17. MongoDB's update() and save() methods are used to update document into a collection. The update() method updates the values in the existing document while the save() method replaces the existing document with the document passed in save() method. MongoDB Update() Method The update() method updates the values in the existing document. Syntax The basic syntax of update() method is as follows − >db.COLLECTION_NAME.update(SELECTION_CRITERIA, UPDATED_DATA)
  • 18. { "_id" : ObjectId(5983548781331adf45ec5), "title":"MongoDB Overview"} { "_id" : ObjectId(5983548781331adf45ec6), "title":"NoSQL Overview"} { "_id" : ObjectId(5983548781331adf45ec7), "title":"Tutorials Point Overview"} >db.mycol.update({'title':'MongoDB Overview'},{$set:{'title':'New MongoDB Tutorial'}}) WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 }) >db.mycol.find() { "_id" : ObjectId(5983548781331adf45ec5), "title":"New MongoDB Tutorial"} { "_id" : ObjectId(5983548781331adf45ec6), "title":"NoSQL Overview"} { "_id" : ObjectId(5983548781331adf45ec7), "title":"Tutorials Point Overview"}
  • 19. By default, MongoDB will update only a single document. To update multiple documents, you need to set a parameter 'multi' to true. >db.mycol.update({'title':'MongoDB Overview'}, {$set:{'title':'New MongoDB Tutorial'}},{multi:true})
  • 20. MongoDB Save() Method The save() method replaces the existing document with the new document passed in the save() method. Syntax The basic syntax of MongoDB save() method is shown below − >db.COLLECTION_NAME.save({_id:ObjectId(),NEW_DATA})
  • 21. MongoDB - Delete Document The remove() Method MongoDB's remove() method is used to remove a document from the collection. remove() method accepts two parameters. One is deletion criteria and second is justOne flag. deletion criteria − (Optional) deletion criteria according to documents will be removed. justOne − (Optional) if set to true or 1, then remove only one document. Syntax Basic syntax of remove() method is as follows − >db.COLLECTION_NAME.remove(DELLETION_CRITTERIA)
  • 22. Example Consider the mycol collection has the following data. {_id : ObjectId("507f191e810c19729de860e1"), title: "MongoDB Overview"}, {_id : ObjectId("507f191e810c19729de860e2"), title: "NoSQL Overview"}, {_id : ObjectId("507f191e810c19729de860e3"), title: "Tutorials Point Overview"} >db.mycol.remove({'title':'MongoDB Overview'}) WriteResult({"nRemoved" : 1}) > db.mycol.find() {"_id" : ObjectId("507f191e810c19729de860e2"), "title" : "NoSQL Overview" } {"_id" : ObjectId("507f191e810c19729de860e3"), "title" : "Tutorials Point Overview" }
  • 23. Remove Only One If there are multiple records and you want to delete only the first record, then set justOne parameter in remove() method. >db.COLLECTION_NAME.remove(DELETION_CRITERIA,1)
  • 24. Remove All Documents If you don't specify deletion criteria, then MongoDB will delete whole documents from the collection. This is equivalent of SQL's truncate command. > db.mycol.remove({}) WriteResult({ "nRemoved" : 2 }) > db.mycol.find() >
  • 25. Cassandra Apache Cassandra is an open source, distributed and decentralized/distributed storage system (database), for managing very large amounts of structured data spread out across the world. It provides highly available service with no single point of failure. It is scalable, fault-tolerant, and consistent. Apache Cassandra is a highly scalable, high-performance distributed database designed to handle large amounts of data across many commodity servers, providing high availability with no single point of failure. It is a type of NoSQL database.
  • 26. Features of Cassandra Cassandra has become so popular because of its outstanding technical features. Given below are some of the features of Cassandra: Elastic scalability − Cassandra is highly scalable; it allows to add more hardware to accommodate more customers and more data as per requirement. Always on architecture − Cassandra has no single point of failure and it is continuously available for business-critical applications that cannot afford a failure. Fast linear-scale performance − Cassandra is linearly scalable, i.e., it increases your throughput as you increase the number of nodes in the cluster. Therefore it maintains a quick response time. Flexible data storage − Cassandra accommodates all possible data formats including: structured, semi-structured, and unstructured. It can dynamically accommodate changes to your data structures according to your need. Easy data distribution − Cassandra provides the flexibility to distribute data where you need by replicating data across multiple data centers. Transaction support − Cassandra supports properties like Atomicity, Consistency, Isolation, and Durability (ACID). Fast writes − Cassandra was designed to run on cheap commodity hardware. It performs blazingly fast writes and can store hundreds of terabytes of data, without sacrificing the read efficiency.
  • 27. History of Cassandra Cassandra was developed at Facebook for inbox search. It was open-sourced by Facebook in July 2008. Cassandra was accepted into Apache Incubator in March 2009. It was made an Apache top-level project since February 2010.
  • 28. Hbase HBase is a data model that is similar to Google’s big table designed to provide quick random access to huge amounts of structured data.
  • 29.
  • 30. TheCAPtheorem,originallyintroducedastheCAPprinciple,canbeusedto explainsomeofthecompetingrequirementsina distributed systemwithreplication.Itisa toolusedto makesystemdesignersaware ofthetrade-offswhiledesigningnetworked trade-offswhiledesigningnetworkedshared-data systems. ThethreelettersinCAPreferto threedesirableproperties ofdistributed systemswith replicateddata: consistency(among
  • 31. Consistency– Consistencymeansthat thenodeswillhavethesamecopiesofa replicateddata itemvisibleforvarious transactions.A various transactions. Aguaranteethateverynodeina distributed clusterreturnsthesame,mostrecent,successfulwrite. recent,successfulwrite.Consistencyreferstoeveryclienthavingthesameviewofthedata. Therearevarious typesof Therearevarious types ofconsistencymodels.ConsistencyinCAPrefersto sequentialconsistency,averystrongformof consistency,a verystrongformofconsistency. Availability – Availability meansthat eachreadorwriterequestforadata itemwilleitherbeprocessedsuccessfullyorwillreceiveamessage successfullyorwillreceivea messagethat theoperation cannotbecompleted.Everynon-failingnodereturnsaresponseforall nodereturnsaresponseforallreadandwrite requestsina reasonableamount oftime.Thekeyword hereis every.Tobe wordhereisevery.Tobeavailable,everynodeon(eithersideofanetworkpartition) mustbeableto respondinareasonable ableto respondinareasonableamount oftime.
  • 32. Partition Tolerant– Partition tolerancemeansthat thesystem cancontinueoperatingifthenetworkconnectingthenodeshasa faultthat results in nodeshasafaultthatresultsin two ormorepartitions, wherethenodesineachpartition canonlycommunicateamong each onlycommunicateamongeachother.Thatmeans,thesystemcontinuesto functionandupholds its consistencyguarantees in upholdsitsconsistencyguaranteesinspiteofnetworkpartitions. Networkpartitions areafactoflife.Distributed systems oflife.Distributed systemsguaranteeingpartition tolerancecangracefullyrecoverfrompartitions oncethepartition heals. partitions oncethepartition heals.