 nosql concepts  mongodb concepts  mongodb demos agenda

Download  NoSQL Concepts  MongoDB Concepts  MongoDB Demos Agenda

Post on 29-Dec-2015




6 download

Embed Size (px)


Tpicos de Bancos de Dados

WTT 2014 - Workshop de Tendncias Tecnolgicas 2014

1NoSQL ConceptsMongoDB ConceptsMongoDB Demos


NoSQL = No SQL = Not using traditional relational DBMSNo SQL Dont use SQL language

Alternative to traditional relational DBMS Flexible schema Quicker/cheaper to set up Massive scalability Relaxed consistency higher performance & availability No declarative query language more programming Relaxed consistency fewer guarantees

NoSQL databases?

NoSQL SystemsMap Reduce Framework Originally from Google, open source Hadoop

Key-Values-Stores Google BigTable, Amazon Dynamo, Cassandra, HBase,

Document Stores Data model: (key, document) pairs Document: JSON, XML, other semistructured formats CouchDB, MongoDB, SimpleDB,

Graph Database Systems Neo4j, FlockDB, Pregel,

Big-Table Implementation Teradata, Exadata, GreenPlum, MonetDB,

Map Reduce FrameworkOriginally from Google, open source Hadoop No data model, data stored in files User provides specific functions as Map ReduceKey-Values-Stores Data model: (key, value) pairsSome allow (non-uniform) columns within valueDocument Stores Data model: (key, document) pairs Document: JSON, XML, other semistructured formats Graph Database Systems Data model: nodes and edges Single-step versus path expressions versus full recursionBig-Table Implementation Data model: RDBM Column stores x Row stores4ACID versus BASE ACID Atomicity,Consistency,Isolation,Durability Traditional Databases

CAP StrongConsistency + HighAvailability + Partition-tolerance

The CAP-Theorem postulates that only two of the three different aspects of scaling out are can be achieved fully at the same time.

Many of the NOSQL BASE BasicallyAvailable,Soft-state,Eventually consistent

ACID(Atomicity,Consistency,Isolation,Durability) Traditional Databases Scaling out of ACID-compliant systems has shown to be a problem. Conflicts are arising between the different aspects of high availability in distributed systems that are not fully solvable.

CAPStrongConsistency: all clients see the same version of the data, even on updates to the dataset - e. g. by means of thetwo-phase commitprotocol (XAtransactions), and ACID,HighAvailability: all clients can always find at least one copy of the requested data, even if some of the machines in a cluster is down,Partition-tolerance: the total system keeps its characteristic even when being deployed on different servers, transparent to the client.

The CAP-Theorem postulates that only two of the three different aspects of scaling out are can be achieved fully at the same time.

Many of the NOSQL databases above all have loosened up the requirements onConsistency in order to achieve betterAvailability andPartitioning. This resulted in systems know asBASE(BasicallyAvailable,Soft-state,Eventually consistent)5Quiz. NoSQL Applications ?[ ] Web Log Analysis URL, timestamp, number of accesses

[ ] Social-network graphs user1, user2, Find friends of a friends

[ ] Wikipedia Pages Large collections, structured and unstructured data

[ ] Twitter messages unstructured data

[ ] Blog maintenance unstructured data

[ ] Account credits and debts

6MongoDBMongoDB (from "humongous") is anopen-sourcedocument database, and theleading NoSQL database. Written in C++, MongoDB features

Document-Oriented StorageQueryingFull Index SupportReplication & High AvailabilityAuto-ShardingMap/ReduceGeospatial supportText Search

7DB-Engines Ranking

8SQL to MongoDB Mapping Chart

http://docs.mongodb.org/manual/reference/sql-comparison/9JSON x SQL x BSON

JSONJavaScript Object Notation. A human-readable, plain text format for expressing structured data with support in many programming languages.

BSONA serialization format used to store documents and make remote procedure calls in MongoDB. BSON is a portmanteau of the words binary and JSON. SQL Schema StatementsMongoDB Schema StatementsCREATE TABLE users ( Id INT NOT NULL AUTO_INCREMENT, user_id Varchar(30), age Number, status char(1), PRIMARY KEY (id) ) db.users.insert( { user_id: "abc123", age: 55, status: "A" } ) 10var p = {_id: 3432,author: DBRef(User, 2), title: Introduction to MongoDB,body: MongoDB is an open sources.. ,timestamp: Date(01-04-12),tags: [MongoDB, NoSQL],comments: [{author: DBRef(User, 4),date: Date(02-04-12),text: Did you see.. ,upvotes: 7, ]}> db.posts.save(p);JSON Document Model

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});Indexes

// find posts which has MongoDB tag.> db.posts.find({tags: MongoDB});

// find posts by authors comments.> db.posts.find({comments.author: DBRef(User,2)}).count();

// find posts written after 31st March. > db.posts.find({timestamp: {gte: Date(31-03-12)}});

// find posts written by authors around [22, 42]> db.posts.find({author.location: {near:[22, 42]});Queries? $gt, $lt, $gte, $lte, $ne, $all, $in, $nin, count, limit, skip, group, etc

db.posts.update({_id: 3432}, {title: Introduction to MongoDB (updated), text: Updated text, ${addToSet: {tags: webinar}});Updates? Atomic Operations$set, $unsetMongoDB does not support TRANSACTIONS ! $push, $pull, $pop, $addToSet$inc, $decr, many more

Some Cool features, but not in this lab Geo-spatial Indexes for Geo-spatial queries.$near, $within_distance, Bound queries (circle, box)

Map/ReduceGROUP BY in SQL, map/reduce in MongoDB.

GridFSStores Large Binary Files.

Demo: my bond girls database

Demo: mongodb installhttp://www.mongodb.org/downloadshttp://docs.mongodb.org/manual/tutorial/install-mongodb-on-windows/

C:\mongodb\bin\mongod.exe --dbpath d:\test\mongodb\data

Demo: mongodb as a Service https://mongolab.com/welcome/

Demo: pymongo

Demo: mongolab create a account

Demo: after a Collection, create a document

Demo: find( ) with Python

Demo: find( ) with mongo shell

Demo: load a .CSV collection with mongo shell

Demo: results of load a .CSV collection

Demo: find( ) a document with mongo shell

Demo: find( ) a document with Python

Demo: find( ) select a field References

The little Mongodb Book by Karl Seguinhttp://openmymind.net/mongodb.pdf

Mongodbhttp://docs.mongodb.org/manual/reference/sql-comparison/http://www.mongodb.org/downloadshttp://docs.mongodb.org/manual/installation/http://docs.mongodb.org/manual/tutorial/getting-started-with-the-mongo-shell/http://docs.mongodb.org/manual/https://www.mongodb.com/reference https://university.mongodb.com


Pymongo, mongodb drive for Pythonhttp://api.mongodb.org/python/current/installation.htmlhttp://api.mongodb.org/python/current/tutorial.html

Easy Install, to install pymongo for Windows https://pypi.python.org/pypi/setuptoolsAlsoPymongo driverhttp://blog.pythonisito.com/2012/01/getting-started-with-mongodb-and-python.htmlJSON exampleshttp://www.jquery4u.com/json/10-example-json-files/

https://mongolab.com/welcome/Account name MackLabMongoDBUsername Rogerio


View more >