Understanding basics of MongoDB and MySQL

Similar documents
Part 1: Installing MongoDB

DATABASES SQL INFOTEK SOLUTIONS TEAM

MongoDB Tutorial for Beginners

Oral Questions and Answers (DBMS LAB) Questions & Answers- DBMS

Making MongoDB Accessible to All. Brody Messmer Product Owner DataDirect On-Premise Drivers Progress Software

NOSQL EGCO321 DATABASE SYSTEMS KANAT POOLSAWASD DEPARTMENT OF COMPUTER ENGINEERING MAHIDOL UNIVERSITY

Advanced Database Project: Document Stores and MongoDB

KurentoRepository Documentation

Big Data Exercises. Fall 2016 Week 11 ETH Zurich

Performance Comparison of NOSQL Database Cassandra and SQL Server for Large Databases

3 / 120. MySQL 8.0. Frédéric Descamps - MySQL Community Manager - Oracle

MongoDB An Overview. 21-Oct Socrates

Introduction to Big Data. NoSQL Databases. Instituto Politécnico de Tomar. Ricardo Campos

NoSQL Databases Analysis

Course Content MongoDB

MySQL Document Store. How to replace a NoSQL database by MySQL without effort but with a lot of gains?

Migrating Oracle Databases To Cassandra

A Review to the Approach for Transformation of Data from MySQL to NoSQL

What is database? Types and Examples

NoSQL DBs and MongoDB DATA SCIENCE BOOTCAMP

NoSQL Injection SEC642. Advanced Web App Penetration Testing, Ethical Hacking, and Exploitation Techniques S

Topics. History. Architecture. MongoDB, Mongoose - RDBMS - SQL. - NoSQL

Cassandra- A Distributed Database

MongoDB to Simplify Your Database Structure

Chapter 24 NOSQL Databases and Big Data Storage Systems

MongoDB. copyright 2011 Trainologic LTD

Cassandra, MongoDB, and HBase. Cassandra, MongoDB, and HBase. I have chosen these three due to their recent

Accessing other data fdw, dblink, pglogical, plproxy,...

Networks and Web for Health Informatics (HINF 6220)

InterConnect. Global initiative on gene environment interactions in diabetes / obesity in specific populations. Grant agreement no:

Implementing Table Operations Using Structured Query Language (SQL) Using Multiple Operations. SQL: Structured Query Language

MONGODB - QUICK GUIDE MONGODB OVERVIEW

CS6312 DATABASE MANAGEMENT SYSTEMS LABORATORY L T P C

DATABASE SYSTEMS. Database programming in a web environment. Database System Course,

relational Key-value Graph Object Document

Big Data Exercises. Fall 2017 Week 11 ETH Zurich

Intro to MongoDB. Alex Sharp.

Uniform Query Framework for Relational and NoSQL Databases

Open source, high performance database. July 2012

MongoDB - a No SQL Database What you need to know as an Oracle DBA

CSE 344: Section 1 Git Setup for HW Introduction to SQLite. September 28, 2017

Mysql Tutorial Create Database User Grant All Specification

NoSQL Databases. Amir H. Payberah. Swedish Institute of Computer Science. April 10, 2014

SQLite vs. MongoDB for Big Data

Import, Export, Index MongoDB

I Have to Support What?!?! A side by side comparison of SQL Server, Oracle, and MongoDB

MongoDB Step By Step. By B.A.Khivsara Assistant Professor Department of Computer Engineering SNJB s COE,Chandwad

Distributed Databases: SQL vs NoSQL

CS 445 Introduction to Database Systems

MySQL Introduction. By Prof. B.A.Khivsara

B.H.GARDI COLLEGE OF MASTER OF COMPUTER APPLICATION. Ch. 1 :- Introduction Database Management System - 1

SQL Commands & Mongo DB New Syllabus

Introduction to NoSQL Databases

Mongo DB NO-SQL Lecture Notes

CSE 530A. Non-Relational Databases. Washington University Fall 2013

Course Introduction & Foundational Concepts

CSE 344: Section 1 Git Setup for HW Introduction to SQLite

Kim Greene - Introduction

Safe Harbor Statement

CIB Session 12th NoSQL Databases Structures

IELM 511 Information Systems Design Labs 5 and 6. DB creation and Population

CIS 601 Graduate Seminar. Dr. Sunnie S. Chung Dhruv Patel ( ) Kalpesh Sharma ( )

CS193X: Web Programming Fundamentals

IoT Data Storage: Relational & Non-Relational Database Management Systems Performance Comparison

SolarCloud Rapid Data Loggingfrom a Solar Power Plant

MONGODB INTERVIEW QUESTIONS

Chapter 9: MySQL for Server-Side Data Storage

SQL in the Hybrid World

Jargons, Concepts, Scope and Systems. Key Value Stores, Document Stores, Extensible Record Stores. Overview of different scalable relational systems

SQL Interview Questions

Database Availability and Integrity in NoSQL. Fahri Firdausillah [M ]

Granting Read-only Access To An Existing Oracle Schema

PROFESSIONAL. NoSQL. Shashank Tiwari WILEY. John Wiley & Sons, Inc.

Using Relational Databases for Digital Research

CSE 344 Final Review. August 16 th

Enhancing a text collection with a document-oriented database model

PHP: Cookies, Sessions, Databases. CS174. Chris Pollett. Sep 24, 2008.

CSE 544 Principles of Database Management Systems. Magdalena Balazinska Winter 2015 Lecture 14 NoSQL

Lesson 3 Ways of Organising the Data. Chapter-5 L03: "Internet of Things ", Raj Kamal, Publs.: McGraw-Hill Education

YeSQL: Battling the NoSQL Hype Cycle with Postgres

DATABASE SYSTEMS. Database programming in a web environment. Database System Course, 2016

5/2/16. Announcements. NoSQL Motivation. The New Hipster: NoSQL. Serverless. What is the Problem? Database Systems CSE 414

Database Systems CSE 414

Lab IV. Transaction Management. Database Laboratory

Data 101 Which DB, When. Joe Yong Azure SQL Data Warehouse, Program Management Microsoft Corp.

CompSci 516 Database Systems

dinner in the sky with

QUERYING SQL, NOSQL, AND NEWSQL DATABASES TOGETHER AND AT SCALE BAPI CHATTERJEE IBM, INDIA RESEARCH LAB, NEW DELHI, INDIA

Lecture 8. Database vs. Files SQL (I) Introduction to SQL database management systems (DBMS)

MongoDB Schema Design

NOSQL FOR POSTGRESQL

Question Bank IT(402) Unit Database 1. What is database? Ans: A database is a collection of information that is organized so that it can be easily

Shen PingCAP 2017

IoT-FastData-Cloud 에기반한 Container 대응. SmartX-mini Playground

Databases and MySQL: The Basics

FREE AND OPEN SOURCE SOFTWARE CONFERENCE (FOSSC-17) MUSCAT, FEBRUARY 14-15, 2017

What s new in Mongo 4.0. Vinicius Grippa Percona

MIS Database Systems.

BIS Database Management Systems.

Introduction to Relational Databases

Transcription:

Understanding basics of MongoDB and MySQL PSOSM summer school @ IIITH Divyansh Agarwal - Research Associate 3rd July, 2017 Precog Labs, IIIT-Delhi

What is a Database? Organized collection of data. Collection of schemas, tables, queries, reports, views, and other objects. Database Management Systems (DBMS) A software application which allows: Definition, Creation, Querying, Update, and Administration of databases

Why DBMS and not flat files? A Database Management System allows: Handling queries. Handling indexing. Handling access from network. Providing access control (user and/or privileges). Convenient data manipulation.

Types of DBMS to talk about Relational DBMS (SQL) NoSQL DBMS

Relational Database Management Systems (RDBMS) DBMS with relational structure such as tables, columns, rows etc. Supports ACID properties: Atomicity: Transaction requires to follow - All or Nothing Consistency: Transaction to bring DB from one valid state to another. Isolation: Transactions must act sequentially. Durability: A committed transaction must never be lost.

What is MySQL? Open-source, fast and easy-to-use RDBMS ACID compliant Supports large databases (upto 50 million rows or more in a table) Uses Structured Query Language (SQL)

Installing MySQL on your machines If not installed, open your terminals, please! sudo apt-get update sudo apt-get install mysql-server sudo mysql_secure_installation sudo mysql_install_db Check version! mysql --version

MySQL Shell Login Type: mysql -u <username> -p

Creating a database Type: create database <database_name> Show databases

Creating Tables Type: create table <table_name> (column_name, column_type); Drop Table Type: drop table <table_name>

Inserting data into Table Type: insert into <table_name> (field1, field2,...fieldn) values (value1, value2,...valuen); Find all tables in a db Type: show tables;

Querying data from table Type: SELECT field1, field2,...fieldn from <table_name1<, <table_name2>... [WHERE Clause]; Selecting all records from a table : SELECT * from <table_name>

Update data in table Type: update <table_name> set field1 = new_value1, field2 = new_value2 [where clause]

Delete a record from table Type: DELETE FROM table_name [WHERE Clause]

Exporting data from MySQL mysqldump -u root -p database_name table_name > dump.txt

What is MongoDB? MongoDB is an open source, cross-platform, document oriented, database program. Written in C++. It is a NoSQL database program, which uses JSON-like documents to store data.

NoSQL Database NoSQL stands for Not Only SQL. A NoSQL database provides a mechanism for storage and retrieval of data which is modeled in means other than the tabular relations used in relational databases. The fundamental difference between MongoDB and an RDBMS is the underlying data model - A relational database structures data into tables and rows, while MongoDB structures data into collections of JSON documents.

Why use NoSQL databases? Some operations are faster in NoSQL databases owing to the different kind of data structures used for modelling the data. For example, NoSQL uses data structures like document based, key-value pairs, graph databases. Data structures used are viewed as more flexible than relational database tables. NoSQL databases are simpler in design, and a good fit for non-complex queries.

Salient features of MongoDB Document oriented Cross platform NoSQL Free and open source Horizontally scalable Dynamic schema, useful for unstructured data. Client libraries available for all major programming languages - PHP, Python, C++, Ruby etc.

Let s dive deeper into MongoDB!

Installing mongodb on your machine sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10 echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.0 multiverse" sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list sudo apt-get update sudo apt-get install -y mongodb-org (MongoDB should automatically install after this.) sudo service mongod status - to check if mongo instance is running or not sudo pip install pymongo (Python wrapper for mongo)

Using MongoDB Activate the mongo shell by simply typing mongo on the terminal window. use DATABASE_NAME is used to create database. To check your currently selected database, use the command db. If you want to check your databases list, use the command show dbs. MongoDB structure consists of Databases Collections Documents. To delete a particular database, switch to that database and run - db.dropdatabase()

Inserting data into MongoDB Create a collection in your database - db.createcollection("participants") and insert a document - db.participants.insert( {"name":"your name"} ) Automatically create collection and add document - db.presenters.insert( {"name":"divyansh"} ) show collections - To view the collections in your mongodb Delete a particular collection - db.collection_name.drop()

Or instead, take a json document - post = { name : Divyansh, age : 22, college : IIIT-D, email: divyansha@iiitd.ac.in, interests: [ Social computing, DBMS, ML ], likes: 100 } db.participants.insert( post )

Querying data from MongoDB db.collectionname.find() - Lists all the documents in the collection db.collectionname.findone() - Lists one document from the collection db.collectionname.find()[2] - Lists one specific document from the collection db.collectionname.findone().pretty() - Prettify the document db.collectionname.find().limit(number) - Display specified number of documents

Advanced querying Conditional query syntax - db.collectionname.find( {<key>:<value>} ) Example : db.collectionname.find( {name: Divyansh } ) Pretty print - db.collectionname.find( {name: Divyansh } ).pretty() db.mycol.find({name:{$ne: Divyansh }}) - Fetch documents with names except Divyansh.

Updating documents in MongoDB Basic syntax - db.collectionname.update(selection_criteria, Updated_Data) db.collectionname.update({'title':'new_title'},{$set:{'title':'new_name'}}) To update multiple documents in one command - db.collectionname.update({'title':'new_title'}, {$set:{'title':'new_name'} },{multi:true})

Removing a document in MongoDB db.collectionname.remove( {<key>:<value>} ) - Removes all the documents which matches the given condition. db.collectionname.remove( {<key>:<value>}, 1) - Removes one document which matches the given condition. db.presenters.remove({ name : Divyansh },1) - Remove the document where the name is Divyansh

Exporting data from mongodb Exporting to json : mongoexport --db <db_name> --collection <collection_name> --out filename.json mongoexport --db new_db --collection mycollection --out mycollection.json Taking a dump of mongo: mongodump --db <db_name> Exporting to CSV: Convert bson dump to csv using - bsondump collection.bson > file.csv Using mongoexport: mongoexport --db <db_name> --collection <collection_name> --type=csv --fields=field1,field2,field3 --out filename.csv

MySQL v/s MongoDB MongoDB uses dynamic schemas, meaning that you can create records without first defining the structure, such as the fields or the types of their values. Whereas, MySQL first defines the schema, and then enters records into the table, based on the schema. MySQL is vertically scalable, whereas MongoDB is horizontally scalable. MongoDB has a more flexible data model compared to MySQL. This means that the database schema can evolve with the requirements of the application. Schema changes that might take hours to change in a MySQL data base, take only a few hours with MongoDB.

Development is simplified with MongoDB, but there are use cases for which a relational database like MySQL would be better suited. SQL also takes care of data redundancy issues, whereas MongoDB doesn t. SQL implements data integrity, whereas MongoDB permits any kind of data to be saved in a document field. There are many examples of hybrid deployments of MongoDB and MySQL. Many e-commerce applications use a combination of MongoDB and MySQL.

Thank you! divyansha@iiitd.ac.in precog.iiitd.edu.in