mongodb

28
MONGO DB

Upload: saravanan-gopalakrishnan

Post on 12-Apr-2017

49 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Mongodb

MONGO DB

Page 2: Mongodb

MONGO DB MongoDB is a cross-platform, document oriented

database that provides, high performance, high availability and easy scalability.

MongoDB works on concept of collection and document.

Page 3: Mongodb

MONGO DBDeveloped by 10gen

Founded in 2007 A document-oriented, NoSQL database

Hash-based, schema-less database No Data Definition Language In practice, this means it can store hashes with any keys

and values. Keys are a basic data type but in reality stored as strings

Page 4: Mongodb

Contd, Application tracks the schema and mapping Based on JSON – B, B stands for Binary Written in C++ Supports APIs (drivers) in many computer languages,

JavaScript, Python, Ruby, Perl, Java, Scala, C#, C++, Haskell, Erlang.

Page 5: Mongodb

Who uses MongoDB

Page 6: Mongodb

Functionality of MongoDB Dynamic schema No DDL Document-based database Secondary indexes Query language via an API Atomic writes and fully-consistent reads Master-slave replication with automated failover (replica

sets)

Page 7: Mongodb

MongoDB: CAP approach

Focus on Consistency and Partition tolerance

Consistency: All replicas contain the

same version of dataAvailability

System remains operational on failing nodes

Partition tolarence Multiple entry points System remains operational

on system split

CAP Theorem:satisfying all three at

the same time is impossible

Page 8: Mongodb

Document StoreRDBMS MongoDB

Database DatabaseTable, View CollectionRow Document Column FieldIndex IndexJoin Embedded DocumentForeign Key Reference

Page 9: Mongodb

Features Document-Oriented storege Open source Full Index Support Replication & High Availability Auto-Sharding Querying Fast In-Place Updates Map/Reduce functionality.

9

Page 10: Mongodb

Contd, Easy to install and use Detailed documentation Various APIs Community

10

Page 11: Mongodb

Advantages of MongoDB over RDBMS Schema less: MongoDB is a document database in

which one collection holds different documents. Number of fields, content and size of the document can differ from one document to another.

Structure of a single object is clear. No complex joins. Deep query-ability. MongoDB supports dynamic

queries on documents using a document-based query language that's nearly as powerful as SQL.

Page 12: Mongodb

Contd, Ease of scale-out: MongoDB is easy to scale. Conversion/mapping of application objects to database

objects not needed. Uses internal memory for storing the working set,

enabling faster access of data.

Page 13: Mongodb

MySQL Vs MongoDB

START TRANSACTION;INSERT INTO contacts VALUES (NULL, ‘joeblow’);INSERT INTO contact_emails VALUES ( NULL, ”[email protected]”, LAST_INSERT_ID() ), ( NULL, “[email protected]”, LAST_INSERT_ID() );COMMIT;

MongoDB

db.contacts.save( { userName: “joeblow”, emailAddresses: [ “[email protected]”, “[email protected]” ] } );

MySQL

Page 14: Mongodb

CRUDCreate

db.collection.insert( <document> ) db.collection.save( <document> )

Read

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

Page 15: Mongodb

Contd,Update

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

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

Page 16: Mongodb

Create DatabaseThe use Command,

MongoDB use DATABASE_NAME is used to create database. The command will create a new database if it doesn't exist, otherwise it will return the existing database.

Syntax use DATABASE_NAME

Page 17: Mongodb

Contd,To check the currently selected database, use the command db.

Syntax >db

To check all database lists use the command Syntax

>show dbsIn MongoDB default database is test. If you didn't create any

database, then collections will be stored in test database.

Page 18: Mongodb

Drop Database

MongoDB dropDatabase() command is used to drop a existing database. Syntax

db.dropDatabase()

This will delete the selected database. If any database is not selected, then it will delete default 'test'

database.

Page 19: Mongodb
Page 20: Mongodb

Create Collection MongoDB createCollection is used to create collection. Syntax

db.createCollection(name, options)

name is name of collection to be created. Options is a document and is used to specify

configuration of collection like memory size and indexing.

To check the created collection by using the command show collections.

Page 21: Mongodb

Method 1:

Page 22: Mongodb

Method 2:

Page 23: Mongodb

Drop a CollectionMongoDB's collection.drop() is used to drop a collection

from the database. Syntax

db.COLLECTION_NAME.drop()

Page 24: Mongodb
Page 25: Mongodb

Disadvantages Usage of memory- server will need lot of RAM Less flexibility with querying (eg. No joins) No Support for transactions. Concurrency issues

Page 26: Mongodb

QUERIES???

Page 27: Mongodb

REFERENCES

•www.tutorialspoint/mongodb•www.mongodb.com/•www.wikipedia.org/mongodb

Page 28: Mongodb

THANK YOU!!!