Mongo DB

What is MongoDB?

MongoDB is a NoSQL store - NoSQL revolution happened to solve the many issues faced with storing web-scale data in relational databases.

It doesn't use SQL to store and retrieve data

Widely adopted in web applications these days

No clear winner and therefore difficult to choose among alternatives

MongoDB, INC

Formerly known as “10Gen”

Name choice comes from the word hu’mongo’us (very large)

Development Began 2007

First Release 2009

Production Ready Version (1.4) 2010

Key Features – MongoDB

The document data model

Ad-hoc queries (A non-standard inquiry.)

Secondary indexes

Replication

Speed & Durability

Scaling

Agile (Dynamic Schemas)

Employee Collection

{ "Name": "Joe",

"state": "delhi",

"phone": "9876543210",

"age": 23,

"email": "joe@abc.com",

"string": "Hello World"

},

{

"Name": "Marry",

"salary": "delhi"

}

]

CURD

Create

db.collection.insert( <document> )

db.collection.save( <document> )

db.collection.update( <query>, <update>, { upsert: true } )

Read

db.collection.find( <query>, <projection> )

db.collection.findOne( <query>, <projection> )

Update

db.collection.update( <query>, <update>, <options> )

Delete

db.collection.remove( <query>, <justOne> )

INSERT

var staffMember = {

"StaffId": 49678,

"FirstName": "Mark",

"LastName": "Wilson",

"HomeAddress": {

"Street": "123HighStreet",

"City": "Anytown",

"PostCode": "AB12DW",

"Country": "England"

},

"Hobbies": [

"Swimming",

"Reading"

]

}

db.Staff.insert(staffMember);

Find

var query = {"LastName": "Wilson"}

db.Staff.find(query)

var query = {"LastName": "Wilson", "FirstName": "Mark"}

db.Staff.find(query)

var query = { $or: [ {"LastName": "Wilson" }, {"LastName": "Easton"} ] }

db.Staff.find(query)

var query = { "FirstName":"Silvia",

$or: [ {"LastName": "Wilson" }, {"LastName": "Easton"} ] }

db.Staff.find(query)

Operators: $in, $gt, $gte, $lt, $lte, $exists... and many more

Remove

b.Staff.remove()

db.Staff.remove({"LastName": "Wilson"})

Update

b.Staff.update({"LastName": "Easton"}, {“FirstName”: “Susan”})

{

"_id" : ObjectId("525bded60b11b9f6614c2ad7"),

"FirstName" : "Susan"

}

db.Staff.update({"FirstName": "Susan"}, {$set: {"LastName": "Easton"}})

db.Staff.update({"LastName": "Easton"}, {“FirstName”: “Susan”})

{

"_id" : ObjectId("525bded60b11b9f6614c2ad7"),

"FirstName" : "Susan"

}

db.Staff.update({"FirstName": "Susanne"}, {$set: {"LastName": "Easton"}})

db.Staff.update({"FirstName": "Susanne"}, {$set: {"LastName": "Easton"}}, true)

{

"_id" : ObjectId("525c7edb3aafe4a7fc6894eb"),

"FirstName" : "Susanne",

"LastName" : "Easton"

}

How can we take advantageof MongoDB in ColdFusion?

<cfsavecontent variable=”StaffJSON”>

{

“StaffId”: 49678,

“FirstName”: “Mark”,

“LastName”: “Wilson”,

“HomeAddress”: {

“Street”: “123 High Street”,

“City”: “Anytown”,

“PostCode”: “AB1 2DW”,

“Country”: “England”

},

“Hobbies”: [“Swimming”, “Reading”]

}

</cfsavecontent>

<cfset Staff = DeserializeJSON(StaffJSON)>

CFML Style

<cfset Mongo = CreateObject("java","com.mongodb.MongoClient")>

<cfset Mongo.init("127.0.0.1")>

<cfset db = Mongo.getDatabase('MongoDB')>

<cfset StaffMember = StructNew()>

<cfset StaffMember.StaffId = 49678>

<cfset StaffMember.FirstName = “Mark”>

<cfset StaffMember.LastName = “Wilson”>

<cfset Staff = mongo.getDbCollection(“Staff”)>

<cfset response = Staff.save(StaffMember)>

Cfscript Style

<cfscript>

StaffMember = {StaffId=49678, FirstName="Mark", LastName="Wilson"};

Staff = mongo.getDbCollection(“Staff”);

Staff.save(StaffMember)>

</cfscript>

<cfscript>

newStaff = [];

arrayAppend (newStaff, {StaffId=49678, FirstName="Mark",

LastName="Wilson"});

arrayAppend (newStaff, {StaffId=76726, FirstName="Tina",

LastName="Lane"});

Staff = mongo.getDbCollection(“Staff”);

Staff.saveAll(newStaff)>

</cfscript>

Database Management System

RDBMS - A Relational database management system (RDBMS) is a database management system (DBMS) that is based on the relational model as introduced by E. F. Codd.

OLAP - Online Analytical Processing.OLAP performs multidimensional analysis of business data and provides the capability for complex calculations, trend analysis, and sophisticated data modeling.

NoSQL - A NoSQL(originally referring to "non SQL" or "non relational") database provides a mechanism for storage and retrieval of data which is modeled in means other than the tabular relations used in relational databases.

Characteristics of NoSQL

Non – Relational

Open – Source

Cluster – Friendly

21st Century Web

Schema – Less

Types of NoSQL Databases

Key – Value (Memcached, Redis, Riak, VoltDB, Amazon DynamoDB)

Graph Databases (InifiniteGraph, Neo4J, OrientDB)

Column Store Databases (Apache HBase, Cassandra, Google’s BigTable)

Document-Oriented Databases (Couchbase, CouchDB, MongoDB, Riak)

Lucid Solutions represents a modern solution for a range of big data challenges by speeding up development and simplifying operations to ensure scale and performance that companies demand. Lucid Solutions delivers a sophisticated solution on MongoDB that addresses big data requirements while inspiring new ideas for applications.

Leave a Reply