for Beginners
ABSTRACT
 This PPT will explain about the MONGODB concepts and using that can
achieve the CURD Operation.
What is MongoDB
 It is a Open source cross platform document oriented with the scalability
and flexible database.
 MongoDB is a distributed database at its core, so high availability,
horizontal scaling, and geographic distribution are built in and easy to use.
 Its Classified as NOSQL database program.
 There is no RDBMS Concept here and data’s are stored in a flat file system.
 MongoDB uses JSON-like documents with SCHEMA for creating a new
Table in the DB. 
Key Features:
 High Performance:
 Support for embedded data models reduces I/O activity on database system.
 Indexes support faster queries and can include keys from embedded documents and
arrays.
 Rich Query Language.
 High Availability: Automatic failover and data redundancy.
 Horizontal Scalability :
 Sharding distributes data across a cluster of machines.
 MongoDB 3.4 supports creating zones of data based on the shard key. In a balanced
cluster, MongoDB directs reads and writes covered by a zone only to those shards inside
the zone. See the Zones manual page for more information.
 Support for Multiple Storage Engines:
 WiredTiger Storage Engine
 MMAPV1 Storage Engine
 Creating dummy Collection
Example :
export var dummytable= new Mongo.Collection(null);
Where we use the MongoDB
 You need High Availability in an Unreliable Environment (Cloud and Real
Life)
 You need to Grow Big (and Shard Your Data)
 Your Data is Location Based
 Your Data Set is Going to be Big (starting from 1GB) and Schema is Not
Stable
 You Don't have a DBA
Comparison Between MYSQL and
MONGODB
List Of Companies Using MongoDB
Installation Steps for MongoDB
 It will support all Operating System. The below links will used for install the
mongoDB
https://docs.mongodb.com/manual/installation/
https://www.mongodb.com/
CREATE A NEW TABLE
 We have a create a new table in MongoDB using Schema.
 In that Schema it self we can add fields and there properties of the table.
 Sample Schema for create a new table in Mongo DB. File name eg :
SampleDB.js
var sampletable= new SimpleSchema({
id: {
type: Number,
label: "ID",
optional: true //It mean the field is Mandatory
},
name: {
type: String,
label: "Name",
optional: true
},
bloodgroup: {
type: String,
label: "BloodGroup",
},
phonenumber: {
type: Number,
label: "Phone Number",
optional: true
},
Date: {
type: Date,
label: "Phone Number",
optional: true
},
});
export const Test = new Mongo.Collection('test');
Test.attachSchema(sampletable);
STORE THE VALUE
 We can store the Value in MongoDB , using INSERT command.
 If we pass a array we can store in to Database.
 The below example contains both array and list the fields are passing to
store the value in Database.
Example : Array value is storing in DB
test.insert({
id: 12345,
name: ’Kesavan’,
bloodgroup:’o+ve’,
phonenumber:’9942591686’,
date:’20180707’
});
QUERY THE RECORD
 To read or query the record in the MongoDB , here its named as finding the record .
 We have to use find(), fetch(), count() and findAll() methods for search the value in
the table.
 find() : It will find the particular record for that we have to pass the _id unique
address of the record.
 fetch() : It will fetch the value for a particular record that we have to pass the _id
unique address of the record.
 count() : It will query the records based on the counts.
 Syntax:
find() and fetch()
db.collection_name.find({ObjectId(12 digit hashcode)}).fetch();
find() and count()
db.collection_name.find({ObjectId(12 digit hashcode)}).count();
Example:
db.test.find({ObjectId(7df78ad8902c)}).fetch()
db.test.find({ObjectId(7df78ad8902c)}).count()
findAll(): we will get all the records in the collection.
Syntax:
db.collection_name.findAll({ });
Example:
db.test.findAll({ }) ;
UPDATE THE VALUE
 For Update the existing record in the MongoDB , we have to use UPDATE
command .
 We can able to update group of record as well as particular record.
 Syntax:
db.collection_name.update({ _id:’value’,fieldname:fieldvalue });
 Example:
test.update({ _id: 7df78ad8902c,phonenumber:’+91-8825719818’})
REMOVE (or)DELETE THE RECORD
 To delete the records in the collection will use REMOVE and DELETE command.
REMOVE:
 It will remove single or multiple the records in the collection the details as below.
 SYNTAX:
db.collection_name.remove({_id});
 To remove the multiple records in the collection use the below logic.
Logic:
var noofrecord= db.collection_name.find().count();
for (i=0;i< noofrecord;i++){
var idval= i._id
db.collection_name.remove({idval});
}
DELETE:
It will delete single or multiple record in the collection the details as mentioned the below.
SYNTAX:
 Delete a single record in the collection.
db.collection_name.deleteOne({_id:ObjectId(“12 digit hash”)});
Example:
db.test.deleteOne({_id:ObjectId(“838383837312”)});
 Delete multiple records in the collection.
db.collection_name.deleteMany({fieldname:fieldvalue)});
Example:
db.test.deleteMany({bloodgroup:’0+ve’)});
DROP THE TABLE
 Using the drop() predefined method will able to delete the entire
collection.
 The below example is explaining about the delete the collection.
 Example:
test.drop()
REFERENCE
 https://www.mongodb.com/
 https://www.meteor.com/tutorials/blaze/collections
 http://meteortips.com/first-meteor-tutorial/databases-part-1/
Note: Based on the mongoDB version lot of methods and functions are
released to get all the updates refer the above links.

MongoDB

  • 1.
  • 2.
    ABSTRACT  This PPTwill explain about the MONGODB concepts and using that can achieve the CURD Operation.
  • 3.
    What is MongoDB It is a Open source cross platform document oriented with the scalability and flexible database.  MongoDB is a distributed database at its core, so high availability, horizontal scaling, and geographic distribution are built in and easy to use.  Its Classified as NOSQL database program.  There is no RDBMS Concept here and data’s are stored in a flat file system.  MongoDB uses JSON-like documents with SCHEMA for creating a new Table in the DB. 
  • 4.
    Key Features:  HighPerformance:  Support for embedded data models reduces I/O activity on database system.  Indexes support faster queries and can include keys from embedded documents and arrays.  Rich Query Language.  High Availability: Automatic failover and data redundancy.  Horizontal Scalability :  Sharding distributes data across a cluster of machines.  MongoDB 3.4 supports creating zones of data based on the shard key. In a balanced cluster, MongoDB directs reads and writes covered by a zone only to those shards inside the zone. See the Zones manual page for more information.
  • 5.
     Support forMultiple Storage Engines:  WiredTiger Storage Engine  MMAPV1 Storage Engine  Creating dummy Collection Example : export var dummytable= new Mongo.Collection(null);
  • 6.
    Where we usethe MongoDB  You need High Availability in an Unreliable Environment (Cloud and Real Life)  You need to Grow Big (and Shard Your Data)  Your Data is Location Based  Your Data Set is Going to be Big (starting from 1GB) and Schema is Not Stable  You Don't have a DBA
  • 7.
  • 8.
    List Of CompaniesUsing MongoDB
  • 9.
    Installation Steps forMongoDB  It will support all Operating System. The below links will used for install the mongoDB https://docs.mongodb.com/manual/installation/ https://www.mongodb.com/
  • 10.
    CREATE A NEWTABLE  We have a create a new table in MongoDB using Schema.  In that Schema it self we can add fields and there properties of the table.  Sample Schema for create a new table in Mongo DB. File name eg : SampleDB.js
  • 11.
    var sampletable= newSimpleSchema({ id: { type: Number, label: "ID", optional: true //It mean the field is Mandatory }, name: { type: String, label: "Name", optional: true }, bloodgroup: { type: String, label: "BloodGroup", }, phonenumber: { type: Number, label: "Phone Number", optional: true }, Date: { type: Date, label: "Phone Number", optional: true }, }); export const Test = new Mongo.Collection('test'); Test.attachSchema(sampletable);
  • 12.
    STORE THE VALUE We can store the Value in MongoDB , using INSERT command.  If we pass a array we can store in to Database.  The below example contains both array and list the fields are passing to store the value in Database. Example : Array value is storing in DB
  • 13.
  • 14.
    QUERY THE RECORD To read or query the record in the MongoDB , here its named as finding the record .  We have to use find(), fetch(), count() and findAll() methods for search the value in the table.  find() : It will find the particular record for that we have to pass the _id unique address of the record.  fetch() : It will fetch the value for a particular record that we have to pass the _id unique address of the record.  count() : It will query the records based on the counts.  Syntax: find() and fetch() db.collection_name.find({ObjectId(12 digit hashcode)}).fetch(); find() and count() db.collection_name.find({ObjectId(12 digit hashcode)}).count();
  • 15.
    Example: db.test.find({ObjectId(7df78ad8902c)}).fetch() db.test.find({ObjectId(7df78ad8902c)}).count() findAll(): we willget all the records in the collection. Syntax: db.collection_name.findAll({ }); Example: db.test.findAll({ }) ;
  • 16.
    UPDATE THE VALUE For Update the existing record in the MongoDB , we have to use UPDATE command .  We can able to update group of record as well as particular record.  Syntax: db.collection_name.update({ _id:’value’,fieldname:fieldvalue });  Example: test.update({ _id: 7df78ad8902c,phonenumber:’+91-8825719818’})
  • 17.
    REMOVE (or)DELETE THERECORD  To delete the records in the collection will use REMOVE and DELETE command. REMOVE:  It will remove single or multiple the records in the collection the details as below.  SYNTAX: db.collection_name.remove({_id});  To remove the multiple records in the collection use the below logic. Logic: var noofrecord= db.collection_name.find().count(); for (i=0;i< noofrecord;i++){ var idval= i._id db.collection_name.remove({idval}); }
  • 18.
    DELETE: It will deletesingle or multiple record in the collection the details as mentioned the below. SYNTAX:  Delete a single record in the collection. db.collection_name.deleteOne({_id:ObjectId(“12 digit hash”)}); Example: db.test.deleteOne({_id:ObjectId(“838383837312”)});  Delete multiple records in the collection. db.collection_name.deleteMany({fieldname:fieldvalue)}); Example: db.test.deleteMany({bloodgroup:’0+ve’)});
  • 19.
    DROP THE TABLE Using the drop() predefined method will able to delete the entire collection.  The below example is explaining about the delete the collection.  Example: test.drop()
  • 20.
    REFERENCE  https://www.mongodb.com/  https://www.meteor.com/tutorials/blaze/collections http://meteortips.com/first-meteor-tutorial/databases-part-1/ Note: Based on the mongoDB version lot of methods and functions are released to get all the updates refer the above links.