Getting Started with MongoDB



Similar documents
L7_L10. MongoDB. Big Data and Analytics by Seema Acharya and Subhashini Chellappan Copyright 2015, WILEY INDIA PVT. LTD.

MongoDB Developer and Administrator Certification Course Agenda

Scaling up = getting a better machine. Scaling out = use another server and add it to your cluster.

MONGODB - THE NOSQL DATABASE

Building Your First MongoDB Application

MongoDB. Or how I learned to stop worrying and love the database. Mathias Stearn. N*SQL Berlin October 22th, gen

Document Oriented Database

Introduction to NoSQL and MongoDB. Kathleen Durant Lesson 20 CS 3200 Northeastern University

The MongoDB Tutorial Introduction for MySQL Users. Stephane Combaudon April 1st, 2014

Hacettepe University Department Of Computer Engineering BBM 471 Database Management Systems Experiment

Please ask questions! Have people used non-relational dbs before? MongoDB?

Big Data & Data Science Course Example using MapReduce. Presented by Juan C. Vega

Building a RESTful service with MongoDB and Spring MVC

MongoDB. An introduction and performance analysis. Seminar Thesis

ADVANCED DATABASES PROJECT. Juan Manuel Benítez V Gledys Sulbaran

SURVEY ON MONGODB: AN OPEN- SOURCE DOCUMENT DATABASE

MongoDB. The Definitive Guide to. The NoSQL Database for Cloud and Desktop Computing. Apress8. Eelco Plugge, Peter Membrey and Tim Hawkins

CSCC09F Programming on the Web. Mongo DB

Brad Dayley. NoSQL with MongoDB

MongoDB: document-oriented database

Dr. Chuck Cartledge. 15 Oct. 2015

A Brief Introduction to MySQL

Scaling with MongoDB. by Michael Schurter Scaling with MongoDB by Michael Schurter - OS Bridge,

DbSchema Tutorial with Introduction in MongoDB

NoSQL Database - mongodb

Frictionless Persistence in.net with MongoDB. Mogens Heller Grabe Trifork

Big Data. Facebook Wall Data using Graph API. Presented by: Prashant Patel Jaykrushna Patel

Open source, high performance database

.NET User Group Bern

NoSQL Databases, part II

Data Model Design for MongoDB

Certified MongoDB Professional VS-1058

Spring Data, Jongo & Co. Java Persistenz-Frameworks für MongoDB

Can the Elephants Handle the NoSQL Onslaught?

NoSQL: Going Beyond Structured Data and RDBMS

Mongo: some travel note Notes taken by Dario Varotto about MongoDB while doing mongo101p, mongo102 and mongo101js courses by MongoDB university.

MongoDB: The Definitive Guide

Visual Statement. NoSQL Data Storage. MongoDB Project. April 10, Bobby Esfandiari Stefan Schielke Nicole Saat

Application of NoSQL Database in Web Crawling

Programming Against Hybrid Databases with Java Handling SQL and NoSQL. Brian Hughes IBM

Cloud Scale Distributed Data Storage. Jürmo Mehine

NoSQL - What we ve learned with mongodb. Paul Pedersen, Deputy CTO paul@10gen.com DAMA SF December 15, 2011

NOSQL INTRODUCTION WITH MONGODB AND RUBY GEOFF

Perl & NoSQL Focus on MongoDB. Jean-Marie Gouarné jmgdoc@cpan.org

these three NoSQL databases because I wanted to see a the two different sides of the CAP

Why NoSQL? Your database options in the new non- relational world IBM Cloudant 1

NoSQL Databases. Nikos Parlavantzas

MongoDB Aggregation and Data Processing Release 3.0.4

Integrating Big Data into the Computing Curricula

Database Management System Choices. Introduction To Database Systems CSE 373 Spring 2013

MongoDB Aggregation and Data Processing

HO5604 Deploying MongoDB. A Scalable, Distributed Database with SUSE Cloud. Alejandro Bonilla. Sales Engineer abonilla@suse.com

Big Data Solutions. Portal Development with MongoDB and Liferay. Solutions

Data storing and data access

Comparing SQL and NOSQL databases

A COMPARATIVE STUDY OF NOSQL DATA STORAGE MODELS FOR BIG DATA

NoSQL web apps. w/ MongoDB, Node.js, AngularJS. Dr. Gerd Jungbluth, NoSQL UG Cologne,

Big data and urban mobility

Overview of Databases On MacOS. Karl Kuehn Automation Engineer RethinkDB

Programming with Genero BDL and NoSQL Databases

Lecture 21: NoSQL III. Monday, April 20, 2015

NORWEGIAN UNIVERSITY OF SCIENCE AND TECHNOLOGY DEPARTMENT OF CHEMICAL ENGINEERING ADVANCED PROCESS SIMULATION. SQL vs. NoSQL

An Approach to Implement Map Reduce with NoSQL Databases

Analytics March 2015 White paper. Why NoSQL? Your database options in the new non-relational world

Integrating VoltDB with Hadoop

Intro to Databases. ACM Webmonkeys 2011

Cloudant Querying Options

MongoDB in the NoSQL and SQL world. Horst Rechner Berlin,

MySQL for Beginners Ed 3

MongoDB Aggregation and Data Processing

How, What, and Where of Data Warehouses for MySQL

D61830GC30. MySQL for Developers. Summary. Introduction. Prerequisites. At Course completion After completing this course, students will be able to:

A basic create statement for a simple student table would look like the following.

NoSQL in der Cloud Why? Andreas Hartmann

Structured Data Storage

SQL. Short introduction

NoSQL replacement for SQLite (for Beatstream) Antti-Jussi Kovalainen Seminar OHJ-1860: NoSQL databases

Oracle Database 10g Express

SQL on NoSQL (and all of the data) With Apache Drill

Linas Virbalas Continuent, Inc.

Not Relational Models For The Management of Large Amount of Astronomical Data. Bruno Martino (IASI/CNR), Memmo Federici (IAPS/INAF)

F1: A Distributed SQL Database That Scales. Presentation by: Alex Degtiar (adegtiar@cmu.edu) /21/2013

DYNAMIC QUERY FORMS WITH NoSQL

RDBMS vs NoSQL: Performance and Scaling Comparison

Database Administration with MySQL

Python and MongoDB. Why?

How graph databases started the multi-model revolution

MongoDB: The Definitive Guide

An Open Source NoSQL solution for Internet Access Logs Analysis

DIPLOMA IN WEBDEVELOPMENT

A table is a collection of related data entries and it consists of columns and rows.

Sharding with postgres_fdw

Benchmarking Couchbase Server for Interactive Applications. By Alexey Diomin and Kirill Grigorchuk

Introduction to MongoDB. Kristina Chodorow

Transcription:

Getting Started with MongoDB TCF IT Professional Conference March 14, 2014 Michael P. Redlich @mpredli about.me/mpredli/ 1 1

Who s Mike? BS in CS from Petrochemical Research Organization Ai-Logix, Inc. (now AudioCodes) Amateur Computer Group of New Jersey Publications Presentations 2 2

Objectives What is MongoDB? What is NoSQL? Getting Started with MongoDB Basic CRUD Operations Live Demos (yea!) MongoDB Resources 3 3

What is MongoDB? (1)...an open-source document database that provides high performance, high availability, and automatic scaling. MongoDB Web Site, http://www.mongodb.org/ It s name derived from humongous Written in C++ 4 4

What is MongoDB? (2)...an open-source database used by companies of all sizes, across all industries and for a wide variety of applications. It is an agile database that allows schemas to change quickly as applications evolve, while still providing functionality developers expect from traditional databases... MongoDB Products Web Site, http://www.mongodb.com/products/mongodb/ 5 5

What is NoSQL? Developed to address shortcomings of a traditional SQL relational database, namely: big data frequency of access to big data performance and scalability 6 6

How is MongoDB Used? 7 7

Who is Using MongoDB? 8 8

Features of MongoDB Document-Oriented Storage Full Index Support Replication and High Availability Auto-Sharding Fast In-Place Updates Map/Reduce GridFS Professional Support by MongoDB Querying 9 9

Nomenclature (1) RDBMS Database Table Row Index Join Foreign Key MongoDB Database Collection Document Index Embedding & Linking Reference 10 10

Nomenclature (2) 11 11

What is a Document? Basic unit of data analogous to a row in a RDBMS An ordered set of fields (keys) with associated values stored in BSON format similar to JSON 12 12

What is BSON?...a binary-encoded serialization of JSON-like documents. BSON Web Site, http://www.bsonspec.org/ Binary JSON Designed to be lightweight, traversable, and efficient 13 13

What is a Collection? A group of documents analogous to a table in a RDBMS Schema-less 14 14

Advantages of Documents Documents correspond to native data types in many programming languages Embedded documents and arrays reduce the need for expensive joins Dynamic schema support fluent polymorphism 15 15

Document Structure { lastname : Redlich, embedded document field firstname : Michael, email : mike@redlich.net role : { officer : President, sig : Java Users Group } } value 16 16

Field Names Strings Cannot contain: null dots (.) dollar sign ($) No duplicate field names 17 17

Conventions Used in This Presentation Command Prompt ($) MySQL prompt (mysql>) MongoDB prompt (>) Keywords (db, find(), etc.) Variables (variable) 18 18

Example Database ACGNJ Board of Directors: lastname firstname roles (embedded documents) tenure 19 19

Getting Started Download MongoDB Create a default data directory /data/db C:\data\db Create your first MongoDB database 20 20

Starting MongoDB Start an instance of the MongoDB server: $ mongod Start an instance of the MongoDB client (a JavaScript-based shell): $ mongo 21 21

Mongo Shell (1) Show the list of shell commands: > help Show the list of databases: > show dbs Show the current database: > db 22 22

Mongo Shell (2) Specify the database to use or create: > use database Show the collections within the current database: > show collections Show the users within the database: > show users 23 23

Mongo Shell (3) Show the recent system.profile entries: > show profile Tab completion Command history 24 24

Primary Key Denoted by a special field, _id It can be generated: Implicitly: {_id : ObjectID(value)} Explicitly: {_id : 2 }, { _id : MPR } 25 25

ObjectIDs Default type for _id A 12-byte hexadecimal BSON type: 26 26

Live Demo! 27 27

Create 28 28

Create a Database Create a database in MySQL: mysql> CREATE DATABASE database; Create a database in MongoDB: > use database 29 29

Create a Collection Create a new table in MySQL: mysql> CREATE TABLE table(column datatype,...); Create a new collection in MongoDB: > db.collection.insert({field:value,...}) 30 30

Insert Data Insert a row in MySQL: > INSERT INTO table(column,...) VALUES(value,...); Insert a document in MongoDB: > db.collection.insert({field:value,...}) 31 31

Insert Data with Loops Insert multiple documents with an array: > for(int i = 0;i < j;++i) db.collection.insert({field:array[i ]}); Insert multiple documents with variable: > for(int i = 0;i < j;++i) db.collection.insert({field:i}) 32 32

Live Demo! 33 33

Read 34 34

Query (1) Retrieve all rows in MySQL: mysql> SELECT * FROM table; Retrieve all documents in MongoDB: > db.collection.find() 35 35

Query (2) Retrieve specified columns in MySQL: mysql> SELECT column1,column2 FROM table; Retrieve specified fields in MongoDB: > db.collection.find({}, {field1:true,field2:true}) 36 36

Query (3) Retrieve specific rows in MySQL: mysql> SELECT * FROM table WHERE column = value; Retrieve specific documents in MongoDB: > db.collection.find({field:value}) 37 37

Query (4) Retrieve specific rows in MySQL: mysql> SELECT * FROM table WHERE column = value ORDER BY value ASC; Retrieve specific documents in MongoDB: > db.collection.find({field:value}).s ort({field:1}) 38 38

Query (5) Query for multiple documents (returns a cursor): > db.collection.find() Query for one document (returns a single document): > db.collection.findone() 39 39

Query Selectors Scalar: $ne, $mod, $exists, $type, $lt, $lte, $gt, $gte Vector: $in, $nin, $all, $size 40 40

Query (6) Retrieve specific rows in MySQL: mysql> SELECT * FROM table WHERE column!= value; Retrieve specific documents in MongoDB: > db.collection.find({field: {$ne:value}}) 41 41

Query (7) Retrieve specific rows in MySQL: mysql> SELECT * FROM table WHERE column1 = value OR column2 = value; Retrieve specific documents in MongoDB: > db.collection.find({$or: [{field:value},{field:value}]) 42 42

Query (8) > db.members.aggregate({$project: {officer:"$roles.officer"}}) > db.members.find({tenure: {$gt:isodate("2014-12-31")}}) > db.members.find({"roles.officer": {$exists:true}}).sort({"roles.offic er":1}) 43 43

Query (9) > db.members.find({"roles.director": {$all:["director"]}}) > db.members.find({"roles.committee": {$in:["historian","newsletter"]}}) > db.members.find({roles:{$size: 3}}) 44 44

Live Demo! 45 45

Update 46 46

Update (1) Update a row in MySQL: mysql> UPDATE table SET column = value WHERE id = id; Update a document in a MongoDB: > db.collection.update({_id:value}, {$set:{field:value}},{multi:true}) 47 47

Update (2) Update a row in MySQL: mysql> UPDATE table SET column1 = value WHERE column2 > value; Update a document in MongoDB: > db.collection.update({field1: {$gt:value}},{$set:{field2:value}}, {multi:true}) 48 48

Update (3) Update a document using findone(): > redlich = db.members.findone({lastname: "Redlich"}) > redlich.roles = [{sig:"java Users Group"}] > db.members.update({lastname: "Redlich"},redlich) 49 49

Atomic Update Operators Scalar: $inc, $set, $unset Vector: $push, $pop, $pull, $pushall, $pullall, $addtoset 50 50

Update (4) > db.members.update({lastname: "Redlich"},{$set: {"ISODate("2016-12-31")}}) > db.members.update({"roles.sig"}, {$set:{"roles.sig":"jug"}}) 51 51

Delete 52 52

Delete (1) Delete all rows in MySQL: mysql> DELETE FROM table; Delete all documents in MongoDB: > db.collection.remove() 53 53

Delete (2) Delete specific rows in MySQL: mysql> DELETE FROM table WHERE column = value; Delete specific documents in MongoDB: > db.collection.remove({field:value}) 54 54

Delete (2) Delete a MySQL database mysql> DROP DATABASE database; Delete a MongoDB database > use database > db.dropdatabase() 55 55

Backup/Restore 56 56

Export (1) Export a collection to a JSON file Ensure mongod is running $ mongoexport --db database -- collection collection --out path/ filename.json 57 57

Export (2) Export a collection to a CSV file Ensure mongod is running A list of fields is required $ mongoexport --db database -- collection collection --fields field1,field2,... --csv --out path/ filename.json 58 58

Import Import a collection from a JSON, CSV, or TSV file Ensure mongod is running $ mongoimport --db database -- collection collection < path/ filename.json 59 59

Dump Dump a specified MySQL database: $ mysqldump -u root --opt database > path.filename.sql Dump all MongoDB databases: Ensure mongod is not running $ mongodump --dbpath /data/db --out path 60 60

Live Demo! 61 61

Package Components (1) Core Processes mongod - core DB process mongos - controller & query router (sharding) mongo - interactive JavaScript-based shell 62 62

Package Components (2) Binary Import and Export mongodump - creates BSON dump files mongorestore - restores BSON dump files bsondump - converts BSON to JSON mongooplog - streams oplog entries 63 63

Package Components (3) Data Import and Export mongoimport - imports JSON, CSV, or TSV data formats mongoexport - exports to JSON, CSV, or TSV data formats 64 64

Package Components (4) Diagnostic Tools mongostat - captures database operations by type (insert, query, etc.) mongotop - tracks read/write activity mongosniff - provides tracing/sniffing view into database activity mongoperf - performance testing tool 65 65

Package Components (5) GridFS mongofiles - provides a command-line interaction to a GridFS storage system 66 66

MongoDB Resources (1) 67 67

MongoDB Resources (2) mongodb.org docs.mongodb.org mongodb.org/books mongodb.com/products/mongodb mongodb.com/reference bsonspec.org education.mongodb.com 68 68

Upcoming Events (1) Trenton Computer Festival March 14-15, 2014 tcf-nj.org Emerging Technologies for the Enterprise April 22-23, 2014 phillyemergingtech.com 69 69

Upcoming Events (2) 70 70

Thanks! mike@redlich.net @mpredli javasig.org 71 71