Presentation is loading. Please wait.

Presentation is loading. Please wait.

MongoDB Introduction, Installation & Execution

Similar presentations


Presentation on theme: "MongoDB Introduction, Installation & Execution"— Presentation transcript:

1 MongoDB Introduction, Installation & Execution
By Prof. B.A.Khivsara Note: The material to prepare this presentation has been taken from internet and are generated only for students reference and not for commercial use.

2 Outline Difference Between SQL and NoSQL
Study of Open Source NOSQL Database MongoDB Installation, Basic CRUD operations, Execution

3 Difference Between SQL and NoSQL
SQL Databases SQL Standard SQL Characteristics SQL Database Examples NoSQL Databases NoSQL Defintion General Characteristics NoSQL Database Types NoSQL Database Examples 12 November 2018

4 SQL Characteristics Data stored in tables
Relationships represented by data Data Manipulation Language Data Definition Language Transactions Abstraction from physical layer 12 November 2018

5 Data Definition Language
Schema defined at the start Create Table Constraints to define and enforce relationships Primary Key Foreign Key Etc. Triggers to respond to Insert, Update , & Delete Stored Modules Alter … Drop … Security and Access Control 12 November 2018

6 Data Manipulation Language (DML)
Data manipulated with Select, Insert, Update, & Delete Data Aggregation Compound statements Functions and Procedures Explicit transaction control 12 November 2018

7 Transactions – ACID Properties
Atomic – All of the work in a transaction completes (commit) or none of it completes Consistent – A transaction transforms the database from one consistent state to another consistent state. Consistency is defined in terms of constraints. Isolated – The results of any changes made during a transaction are not visible until the transaction has committed. Durable – The results of a committed transaction survive failures 12 November 2018

8 Significant portions of the world’s economy use SQL databases!
SQL Database Examples Commercial IBM DB2 Oracle RDMS Microsoft SQL Server Sybase SQL Anywhere Open Source (with commercial options) MySQL Ingres Significant portions of the world’s economy use SQL databases! 12 November 2018

9 NoSQL Definition- From www.nosql-database.org
Next Generation Databases mostly addressing some of the points: non-relational, distributed,  open-source and horizontal scalable. Often more characteristics apply as: schema-free, easy replication support, simple API, eventually consistent / BASE (not ACID), huge data amount, and more. 12 November 2018

10 NoSQL Products/Projects
lists 122 NoSQL Databases Cassandra CouchDB Hadoop & Hbase MongoDB StupidDB Etc. 12 November 2018

11 NoSQL Distinguishing Characteristics
Large data volumes Google’s “big data” Scalable replication and distribution Potentially thousands of machines Potentially distributed around the world Queries need to return answers quickly Schema-less ACID transaction properties are not needed – BASE CAP Theorem Open source development 12 November 2018

12 BASE Transactions Acronym contrived to be the opposite of ACID
Basically Available, Soft state, Eventually Consistent Characteristics Weak consistency – stale data OK Availability first Best effort Approximate answers OK Aggressive (optimistic) Simpler and faster 12 November 2018

13 Brewer’s CAP Theorem CAP Theorem Consistency Availability
Partition tolerance 12 November 2018

14 Consistency all nodes see the same data at the same time – Wikipedia
client perceives that a set of operations has occurred all at once – Pritchett More like Atomic in ACID transaction properties 12 November 2018

15 Availability node failures do not prevent survivors from continuing to operate – Wikipedia Every operation must terminate in an intended response – Pritchett 12 November 2018

16 Partition Tolerance the system continues to operate despite arbitrary message loss – Wikipedia Operations will complete, even if individual components are unavailable – Pritchett 12 November 2018

17 Outline Difference Between SQL and NoSQL
Study of Open Source NOSQL Database MongoDB Installation, Basic CRUD operations, Execution

18 Open Source Small upfront software costs
Suitable for large scale distribution on commodity hardware 12 November 2018

19 NoSQL Database Types Column Store –
Each storage block contains data from only one column Document Store – stores documents made up of tagged elements Key-Value Store – Hash table of keys 12 November 2018

20 Other Non-SQL Databases
XML Databases Graph Databases Codasyl Databases Object Oriented Databases Etc… 12 November 2018

21 NoSQL Example: Column Store
Each storage block contains data from only one column Example: Hadoop/Hbase Yahoo, Facebook Example: Ingres VectorWise Column Store integrated with an SQL database 12 November 2018

22 Column Store Comments More efficient than row (or document) store if:
Multiple row/record/documents are inserted at the same time so updates of column blocks can be aggregated Retrievals access only some of the columns in a row/record/document 12 November 2018

23 NoSQL Examples: Key-Value Store
Hash tables of Keys Values stored with Keys Fast access to small data values Example – Project-Voldemort Linkedin Example – MemCacheDB Backend storage is Berkeley-DB 12 November 2018

24 Map Reduce Technique for indexing and searching large data volumes
Two Phases, Map and Reduce Map Extract sets of Key-Value pairs from underlying data Potentially in Parallel on multiple machines Reduce Merge and sort sets of Key-Value pairs Results may be useful for other searches 12 November 2018

25 Map Reduce Patent Google granted US Patent 7,650,331, January 2010
System and method for efficient large-scale data processing A large-scale data processing system and method includes one or more application-independent map modules configured to read input data and to apply at least one application-specific map operation to the input data to produce intermediate data values, wherein the map operation is automatically parallelized across multiple processors in the parallel processing environment. A plurality of intermediate data structures are used to store the intermediate data values. One or more application-independent reduce modules are configured to retrieve the intermediate data values and to apply at least one application-specific reduce operation to the intermediate data values to provide output data. 12 November 2018

26 NoSQL Example: Document Store
Example: CouchDB BBC Example: MongoDB Foursquare, Shutterfly JSON – JavaScript Object Notation 12 November 2018

27 CouchDB JSON Example { "_id": "guid goes here", "_rev": "314159", "type": "abstract", "author": "Keith W. Hare" "title": "SQL Standard and NoSQL Databases", "body": "NoSQL databases (either no-SQL or Not Only SQL) are currently a hot topic in some parts of computing.", "creation_timestamp": "2011/05/10 13:30: " } 12 November 2018

28 CouchDB JSON Tags "_id" "_rev" "type", "author", "title", etc.
GUID – Global Unique Identifier Passed in or generated by CouchDB "_rev" Revision number Versioning mechanism "type", "author", "title", etc. Arbitrary tags Schema-less Could be validated after the fact by user-written routine 12 November 2018

29 MongoDB

30 What is MongoDB ? • Scalable High-Performance Open-source, Document-orientated database. • Built for Speed • Rich Document based queries for Easy readability. • Full Index Support for High Performance. • Replication and Failover for High Availability. • Auto Sharding for Easy Scalability. • Map / Reduce for Aggregation.

31 Why use MongoDB? • SQL was invented in the 70’s to store data.
• MongoDB stores documents (or) objects. • Now-a-days, everyone works with objects (Python/Ruby/Java/etc.) • And we need Databases to persist our objects. Then why not store objects directly ? • Embedded documents and arrays reduce need for joins. No Joins and No-multi document transactions.

32 What is MongoDB great for?
• RDBMS replacement for Web Applications. • Semi-structured Content Management. • Real-time Analytics & High-Speed Logging. • Caching and High Scalability Web 2.0, Media, SAAS, Gaming HealthCare, Finance, Telecom, Government

33 Some Companies using MongoDB in Production
Not great for? • Highly Transactional Applications. • Problems requiring SQL. Some Companies using MongoDB in Production

34 Advantages of MongoDB Schema less : Number of fields, content and size of the document can be differ from one document to another. No complex joins Data is stored as JSON style Index on any attribute Replication and High availability

35 MongoDB Terminologies for RDBMS concepts
Database Table, View Collection Row Document (JSON, BSON) Column Field Index Join Embedded Document Foreign Key Reference Partition Shard Javascript

36 JSON “JavaScript Object Notation”
Easy for humans to write/read, easy for computers to parse/generate Objects can be nested Built on name/value pairs Ordered list of values

37 BSON “Binary JSON” Binary-encoded serialization of JSON-like docs
Embedded structure reduces need for joins Goals Lightweight Traversable Efficient (decoding and encoding)

38 BSON Example { "_id" : "37010" “City" : “Nashik", “Pin" : 423201,
"state" : “MH", “Postman” : { name: “Ramesh Jadhav” address: “Panchavati” }

39 Data Types of MongoDB Integer Boolean Date Binary data Double
String Arrays Null Object ID Binary data Date

40 Data Types String : This is most commonly used datatype to store the data. String in mongodb must be UTF-8 valid. Integer : This type is used to store a numerical value. Integer can be 32 bit or 64 bit depending upon your server. Boolean : This type is used to store a boolean (true/ false) value. Double : This type is used to store floating point values. Min/ Max keys : This type is used to compare a value against the lowest and highest BSON elements. Arrays : This type is used to store arrays or list or multiple values into one key. Timestamp : ctimestamp. This can be handy for recording when a document has been modified or added. Object : This datatype is used for embedded documents.

41 Data Types Null : This type is used to store a Null value.
Symbol : This datatype is used identically to a string however, it's generally reserved for languages that use a specific symbol type. Date : This datatype is used to store the current date or time in UNIX time format. You can specify your own date time by creating object of Date and passing day, month, year into it. Object ID : This datatype is used to store the document’s ID. Binary data : This datatype is used to store binay data. Code : This datatype is used to store javascript code into document. Regular expression : This datatype is used to store regular expression

42 Outline Difference Between SQL and NoSQL
Study of Open Source NOSQL Database MongoDB Installation, Basic CRUD operations, Execution

43 Find version of Windows
enter the following commands in the Command Prompt or Powershell: wmic os get caption wmic os get osarchitecture

44 Installation in Windows
Download MongoDB from Website: Select option Windows Download and Run

45 Starting MongoDB in Windows
Create one folder (eg SNJB) in bin folder of MongoDB Goto command prompt Goto bin dir of MongoDB and write following command mongod --storageEngine=mmapv1 --dbpath SNJB (Server will started and listen at port) Open another command prompt and give command mongo (Client will be started)

46 Installation in Ubuntu
Download MongoDB from Website: Select option Linux Download and Run

47 Starting MongoDB in Ubuntu
Create a folder in bin directory of mongodb Open terminal Goto mongodb bin folder (cd mongo….) Type ./mongod (Server is started) Open another terminal Type ./mongo (client will be started) Run all commands on client terminal

48 Outline Difference Between SQL and NoSQL
Study of Open Source NOSQL Database MongoDB Installation, Basic CRUD operations, Execution

49 Basic Database Operations
collection

50 Basic Database Operations- Database
switched to database provided with ciommand use <database name> To check currently selected database use the command db db Displays the list of databases show dbs To Drop the database db.dropDatabase()

51 Basic Database Operations- Collection
To create collection db.createCollection (name) Ex:- db.createCollection(Stud) List out all names of collection in current database >show collections In mongodb you don't need to create collection. MongoDB creates collection automatically, when you insert some document. db.databasename.insert ({Key : Value}) Ex:- db.Stud.insert({{Name:”Jiya”}) MongoDB's db.collection.drop() is used to drop a collection from the database. db.collection.drop() Example:- db.Stud.drop()

52 CRUD Operations Insert Find Update Delete

53 References https://docs.mongodb.com/manual/introduction/


Download ppt "MongoDB Introduction, Installation & Execution"

Similar presentations


Ads by Google