Www.luxoft.com Introduction to MongoDB. www.luxoft.com Database compared.

Slides:



Advertisements
Similar presentations
Keys, Referential Integrity and PHP One to Many on the Web.
Advertisements

1 More MongoDB: Ch 3- 8, plus a little Hadoop CSSE 533 Week 2, Spring, 2015.
In 10 minutes Mohannad El Dafrawy Sara Rodriguez Lino Valdivia Jr.
MongoDB Introduction © Zoran Maksimovic
An introduction to MongoDB Rácz Gábor ELTE IK, febr. 10.
Building applications with MongoDB – An introduction Roger
Jeff Lemmerman Matt Chimento Medtronic Confidential 1 9th Annual CodeFreeze Symposium Medtronic Energy and Component Center.
A Social blog using MongoDB ITEC-810 Final Presentation Lucero Soria Supervisor: Dr. Jian Yang.
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation MongoDB Read Lecturer.
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation MongoDB Write Lecturer.
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation MongoDB Data Modeling.
MMG508.  Access Types  Tables  Relational tables  Queries  Stored database queries  Forms  GUI forms for data entry/display  Reports  Reports.
1 Yasin N. Silva Arizona State University This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
MONGODB NOSQL SERIES Karol Rástočný 1. Prominent Users 2  AppScale, bit.ly, Business Insider, CERN LHC, craigslist, diaspora, Disney Interactive Media.
ASP.NET Programming with C# and SQL Server First Edition
MongoDB An introduction. What is MongoDB? The name Mongo is derived from Humongous To say that MongoDB can handle a humongous amount of data Document.
NoSQL continued CMSC 461 Michael Wilson. MongoDB  MongoDB is another NoSQL solution  Provides a bit more structure than a solution like Accumulo  Data.
WTT Workshop de Tendências Tecnológicas 2014
Goodbye rows and tables, hello documents and collections.
NOSQL DATABASES Please remember to read the NOSQL Distilled book and the Seven Databases book.
Methodological Foundations of Biomedical Informatics (BMSC-GA 4449) Himanshu Grover.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
Database: SQL and MySQL
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation Exam and Lecture Overview.
WEEK 1, DAY 2 STEVE CHENOWETH CSSE DEPT CSSE 533 –INTRO TO MONGODB.
MongoDB is a database management system designed for web applications and internet infrastructure. The data model and persistence strategies are built.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
Introduction to MongoDB
MongoDB - Overview - Doctrine ODM - Symfony2 with Doctrine ODM.
Modeling MongoDB with Relational Model Proposed by Christopher Polanco.
MongoDB First Light. Mongo DB Basics Mongo is a document based NoSQL. –A document is just a JSON object. –A collection is just a (large) set of documents.
Mongodb.org A. Im, G. Cai, H. Tunc, J. Stevens, Y. Barve, S. Hei Vanderbilt University.
NOSQL DATABASE Not Only SQL DATABASE
NoSQL: Graph Databases. Databases Why NoSQL Databases?
Introduction to Databases & SQL Ahmet Sacan. What you’ll need Firefox, SQLite plugin Mirdb and Targetscan databases.
Introduction to Database Programming with Python Gary Stewart
COMP 430 Intro. to Database Systems MongoDB. What is MongoDB? “Humongous” DB NoSQL, no schemas DB Lots of similarities with SQL RDBMs, but with more flexibility.
Dive into NoSQL with Azure Niels Naglé Hylke Peek.
Data Management in the Cloud
Introduction to Mongo DB(NO SQL data Base)
CSE-291 (Distributed Systems) Winter 2017 Gregory Kesden
Mongo Database (Intermediate)
NO SQL for SQL DBA Dilip Nayak & Dan Hess.
and Big Data Storage Systems
Lecturer : Dr. Pavle Mogin
CC Procesamiento Masivo de Datos Otoño 2017 Lecture 10: NoSQL II
MongoDB Er. Shiva K. Shrestha ME Computer, NCIT
Presented by Ben Carpenter
Dineesha Suraweera.
MongoDB CRUD Operations
javascript for your data
Aggregation Aggregations operations process data records and return computed results. Aggregation operations group values from multiple documents together,
CSE-291 (Cloud Computing) Fall 2016 Gregory Kesden
MongoDB for Developers
Write Operations.
MongoDB Read/Write.
MongoDB Read/Write.
CMPE 280 Web UI Design and Development October 18 Class Meeting
Write Operations.
MongoDB Read/Write.
CC Procesamiento Masivo de Datos Otoño Lecture 9 NoSQL: MongoDB
Contents Preface I Introduction Lesson Objectives I-2
CS5220 Advanced Topics in Web Programming Introduction to MongoDB
Building applications with MongoDB – An introduction
MongoDB Read.
Lecture 15: Databases II Wednesday Feburary 28, 2018
INTRODUCTION TO MONgodb
NoSQL databases An introduction and comparison between Mongodb and Mysql document store.
MongoDB Read Operations
Server & Tools Business
Presentation transcript:

Introduction to MongoDB

Database compared

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.

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.

What is MongoDB great for? RDBMS replacement for Web Applications. Semi-structured Content Management. Real-time Analytics & High-Speed Logging. Caching and High Scalability

Not great for? Highly Transactional Applications. Problems requiring SQL.

Impedance Mismatch 33red 34blue xname 1AbcAbc 2XyzXyz // your application code class Foo { int x; string [] tags;} tagIdx tagIdtag 2

No Impedance Mismatch // your application code class Foo { int x; string [] tags;} // mongo document for Foo { x: 1, tags: [‘abc’,’xyz’] }

Blog in relational DB

Blog post structure in document DB

Blog post in JSON DB

Database When I say Database Think Made up of Multiple Collections. Created on-the-fly when referenced for the first time.

Collection When I say Table Think Schema-less, and contains Documents. Indexable by one/more keys. Created on-the-fly when referenced for the first time. Capped Collections: Fixed size, older records get dropped after reaching the limit.

Document When I say Record/Row Think Stored in a Collection. Have _id key – works like Primary keys in MySQL. Supported Relationships – Embedded (or) References. Document storage in BSON (Binary form of JSON).

var post = { ‘_id’: ObjectId(‘3432’), ‘author’: ObjectId(‘2311’), ‘title’: ‘Introduction to MongoDB’, ‘body’: ‘MongoDB is an open sources.. ‘, ‘timestamp’: Date(’ ’), ‘tags’: [‘MongoDB’, ‘NoSQL’], ‘comments’: [{‘author’: ObjectId(‘5331’), ‘date’: Date(’ ’), ‘text’: ‘Did you see.. ‘, ‘upvotes’: 7} ] } > db.posts.insert(post); Understanding the Document Model

The Problem  You say:  The server does : (pseudo) db.foo.find({ x: 10 }) for each doc d in ‘foo’{ if ( d.x == 10 ){ return d } Ouch! Reads EVERY document! _id: … x:9 _id: … x:10 _id: … x:9 _id:. x:… Document Storage

The Solution ValueDoc Pointers 9[171, 819, 2309] 10[4376] _id: … x:9 _id: … x:10 _id: … x:9 _id:. x:… Document Storage Index - field ‘x’, collection ‘foo’ db.foo.find({ x:10 })

Create Index db.foo.ensureIndex(keys, options) Name? Build now? Unique Sparse? TTL? Language? Which fields? In what Order? Geo / Text Collection

Create Index on any field in the document // 1 means ascending, -1 means descending > db.posts.ensureIndex({‘author’: 1}); //Index Nested Documents > db.posts.ensureIndex(‘comments.author’: 1); // Index on tags > db.posts.ensureIndex({‘tags’: 1}); // Geo-spatial Index > db.posts.ensureIndex({‘author.location’: ‘2d’}); Secondary Indexes

// find posts which has ‘MongoDB’ tag. > db.posts.find({tags: ‘MongoDB’}); // find posts by author’s comments. > db.posts.find({‘comments.author’: ‘Johnson’}).count(); // find posts written after 31 st March. > db.posts.find({‘timestamp’: {‘$gte’: Date(’ ’)}}); // find posts written by authors around [22, 42] > db.posts.find({‘author.location’: {‘$near’:[22, 42]}); Find $gt, $lt, $gte, $lte, $ne, $all, $in, $nin…

Find Which fields? db.foo.find(query, projection) Which documents?

Find: projection > db.posts.find({}, {title:1}) { "_id" : ObjectId(" f37f63ffc4ebf1964"), "title" : "NodeJS server" } { "_id" : ObjectId(" c37f63ffc4ebf1965"), "title" : "Introduction to MongoDB" } Like select title from posts Empty projection like select * from posts

Find Query criteria Single value field Array field Sub-document / dot notation Find Filed inclusion and exclusion Projection Sort Limit Skip Cursor

Paging example

> db.posts.update( {"_id" : ObjectId(" f37f63ffc4ebf1964")}, { title:"NodeJS server" }); Update: replace the document This will replace the document by { title:"NodeJS server" }

> db.posts.update( {"_id" : ObjectId(" f37f63ffc4ebf1964")}, { $addToSet: {tags:"JS"}, $set: {title:"NodeJS server"}, $unset: { comments: 1} }); Update: change only the part of document $set, $unset $push, $pull, $pop, $addToSet $inc, $decr, many more…

Update db.foo.update(query,update,options); Collection Name Which Document? What Change? One? Many? Upsert? Options: {multi: true} – will change all found documents; by default only first found will be updated {upsert: true} – will insert document if it was not found

Find And Modify db.foo.findAndModify( { query:, update:, upsert:, remove:, new:, sort:, fields: } ); Collection Name Which Document? What Change? Delete it? Return new/old? Query order Return what?

Some Cool features Geo-spatial Indexes for Geo-spatial queries. $near, $within_distance, Bound queries (circle, box) GridFS Stores Large Binary Files. Map/Reduce GROUP BY in SQL, map/reduce in MongoDB.

Replica Sets

Sharding