Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Mongodb1, Study notes of Database Management Systems (DBMS)

abc - abc - abc - abc

Typology: Study notes

2014/2015

Uploaded on 09/07/2015

MRUNALI.YADAV
MRUNALI.YADAV 🇮🇳

1 document

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
MONGODB
WHAT IS MONGODB???
MongoDB (from humongous) is a cross-platform document-oriented database.
Classified as a NoSQL database, MongoDB eschews the traditional table-based
relational database structure in favor of JSON-like documents with dynamic schemas
(MongoDB calls the format BSON), making the integration of data in certain types of
applications easier and faster. Released under a combination of the GNU Affero
General Public License and the Apache License, MongoDB is free and open-source
software.
First developed by the software company 10gen (now MongoDB Inc.) in October 2007
as a component of a planned platform as a service product, the company shifted to an
open source development model in 2009, with 10gen offering commercial support and
other services.[1] Since then, MongoDB has been adopted as backend software by a
number of major websites and services, including Craigslist, eBay, Foursquare
, SourceForge, Viacom, and The New York Times among others.[citation needed] As of 2014,
MongoDB was the most popular NoSQL database system.[2]
MongoDB is one of several database types to arise in the mid-2000s under the
NoSQL banner. Instead of using tables and rows as in relational databases,
MongoDB is built on an architecture of collections and documents. Documents
comprise sets of key-value pairs and are the basic unit of data in MongoDB.
KEY FEATURES OF MONGODB.
Flexibility
MongoDB stores data in JSON documents (which we serialize to
BSON). JSON provides a rich data model that seamlessly maps to
native programming language types, and the dynamic schema
makes it easier to evolve your data model than with a system with
enforced schemas such as a RDBMS.
Power
pf3
pf4
pf5

Partial preview of the text

Download Mongodb1 and more Study notes Database Management Systems (DBMS) in PDF only on Docsity!

MONGODB

WHAT IS MONGODB???

MongoDB (from humongous ) is a cross-platform document-oriented database.

Classified as a NoSQL database, MongoDB eschews the traditional table-based

relational database structure in favor of JSON-like documents with dynamic schemas

(MongoDB calls the format BSON), making the integration of data in certain types of

applications easier and faster. Released under a combination of the GNU Affero

General Public License and the Apache License, MongoDB is free and open-source

software.

First developed by the software company 10gen (now MongoDB Inc.) in October 2007

as a component of a planned platform as a service product, the company shifted to an

open source development model in 2009, with 10gen offering commercial support and

other services. [1]^ Since then, MongoDB has been adopted as backend software by a

number of major websites and services, including Craigslist, eBay, Foursquare

, SourceForge, Viacom, and The New York Times among others. [ citation needed ]^ As of 2014,

MongoDB was the most popular NoSQL database system. [2]

MongoDB is one of several database types to arise in the mid-2000s under the

NoSQL banner. Instead of using tables and rows as in relational databases,

MongoDB is built on an architecture of collections and documents. Documents

comprise sets of key-value pairs and are the basic unit of data in MongoDB.

KEY FEATURES OF MONGODB.

  • Flexibility

MongoDB stores data in JSON documents (which we serialize to

BSON). JSON provides a rich data model that seamlessly maps to

native programming language types, and the dynamic schema

makes it easier to evolve your data model than with a system with

enforced schemas such as a RDBMS.

  • Power

MongoDB provides a lot of the features of a traditional RDBMS

such as secondary indexes, dynamic queries, sorting, rich updates,

upserts (update if document exists, insert if it doesn’t), and easy

aggregation. This gives you the breadth of functionality that you

are used to from an RDBMS, with the flexibility and scaling

capability that the non-relational model allows.

  • Speed/Scaling

By keeping related data together in documents, queries can be

much faster than in a relational database where related data is

separated into multiple tables and then needs to be joined later.

MongoDB also makes it easy to scale out your database.

Autosharding allows you to scale your cluster linearly by adding

more machines. It is possible to increase capacity without any

downtime, which is very important on the web when load can

increase suddenly and bringing down the website for extended

maintenance can cost your business large amounts of revenue.

  • Ease of use

MongoDB works hard to be very easy to install, configure,

maintain, and use. To this end, MongoDB provides few

configuration options, and instead tries to automatically do the

“right thing” whenever possible. This means that MongoDB works

right out of the box, and you can dive right into developing your

application, instead of spending a lot of time fine-tuning obscure

database configurations.

  • NEED OF MONGODB

Why should use MongoDB?

  • Document Oriented Storage : Data is stored in the form of JSON style documents
  • Index on any attribute
  • Replication & High Availability
  • Auto-Sharding
  • Rich Queries

SQL Schema Statements MongoDB Schema Statements

CREATE TABLE users ( id MEDIUMINT NOT NULL AUTO_INCREMENT, user_id Varchar(30), age Number, status char(1), PRIMARY KEY (id) )

Implicitly created on first insert() operation. The primary key

_id is automatically added if _id field is not specified.

db.users.insert( { user_id: "abc123", age: 55, status: "A" } )

However, you can also explicitly create a collection:

db.createCollection("users") ALTER TABLE users ADD join_date DATETIME

Collections do not describe or enforce the structure of its

documents; i.e. there is no structural alteration at the collection

level.

However, at the document level, update() operations can add

fields to existing documents using the $set operator.

db.users.update( { }, { $set: { join_date: new Date() } }, { multi: true } ) ALTER TABLE users DROP COLUMN join_date

Collections do not describe or enforce the structure of its

documents; i.e. there is no structural alteration at the collection

level.

However, at the document level, update() operations can

remove fields from documents using the $unset operator.

db.users.update( { }, { $unset: { join_date: "" } }, { multi: true } ) CREATE INDEX idx_user_id_asc ON users(user_id)

db.users.createIndex( { user_id: 1 } )

CREATE INDEX

idx_user_id_asc_age_desc ON users(user_id, age DESC)

db.users.createIndex( { user_id: 1, age: -1 } )

DROP TABLE users db.users.drop()

Insert

The following table presents the various SQL statements related to inserting records into tables

and the corresponding MongoDB statements.

SQL INSERT Statements MongoDB insert() Statements

INSERT INTO users(user_id, age,

db.users.insert( { user_id: "bcd001", age: 45, status: "A" }

status) VALUES ("bcd001", 45, "A")

Select

The following table presents the various SQL statements related to reading records from tables

and the corresponding MongoDB statements.

SQL SELECT Statements MongoDB find() Statements

SELECT *

FROM users

db.users.find()

SELECT id, user_id, status FROM users

db.users.find( { }, { user_id: 1, status: 1 } ) SELECT user_id, status FROM users

db.users.find( { }, { user_id: 1, status: 1, _id: 0 } ) SELECT * FROM users WHERE status = "A"

db.users.find( { status: "A" } ) SELECT user_id, status FROM users WHERE status = "A"

db.users.find( { status: "A" }, { user_id: 1, status: 1, _id: 0 } ) SELECT * FROM users WHERE status != "A"

db.users.find( { status: { $ne: "A" } } ) SELECT * FROM users WHERE status = "A" AND age = 50

db.users.find( { status: "A", age: 50 } )

SELECT * FROM users WHERE status = "A" OR age = 50

db.users.find( { $or: [ { status: "A" } , { age: 50 } ] } )

SELECT * FROM users WHERE age > 25

db.users.find( { age: { $gt: 25 } } ) SELECT * FROM users WHERE age < 25

db.users.find( { age: { $lt: 25 } } ) SELECT * FROM users WHERE age > 25 AND age <= 50

db.users.find( { age: { $gt: 25, $lte: 50 } } )

SELECT *

FROM users WHERE user_id like "%bc

db.users.find( { user_id: /bc/ } )

UPDATE users SET age = age + 3 WHERE status = "A"

db.users.update( { status: "A" } , { $inc: { age: 3 } }, { multi: true } )

Delete Records

The following table presents the various SQL statements related to deleting records from tables

and the corresponding MongoDB statements.

SQL Delete Statements MongoDB remove() Statements

DELETE FROM users WHERE status = "D"

db.users.remove( { status: "D" } )

DELETE FROM users db.users.remove({})

BIGDATA

Big data is an evolving term that describes any voluminous amount of structured, semi-

structured and unstructured data that has the potential to be mined for information.

Big data is a broad term for data sets so large or complex that traditional data

processing applications are inadequate. Challenges include analysis, capture, data

curation, search, sharing, storage, transfer, visualization, and information privacy. The

term often refers simply to the use of predictive analytics or other certain advanced

methods to extract value from data, and seldom to a particular size of data set.

Accuracy in big data may lead to more confident decision making. And better decisions

can mean greater operational efficiency, cost reductions and reduced risk.