MongoDB for the SQL Server Pro

46
Lynn Langit MongoDB for the SQL Server Pro Feb 2013 – For MongoDB LA

Transcript of MongoDB for the SQL Server Pro

Page 1: MongoDB for the SQL Server Pro

Lynn Langit

MongoDB for the SQL Server Pro

Feb 2013 – For MongoDB LA

Page 2: MongoDB for the SQL Server Pro

What is MongoDB?

• Open source NoSQL database• Document-oriented • Stores JSON-like documents (dynamic schemas)• Includes a strong query language (javascript)• Powerful, flexible indexing (including geospatial)• Sharding and replication• Cross-Platform (many drivers )

Page 3: MongoDB for the SQL Server Pro

QUICKSTART - SETUP MONGODB Demo

Page 4: MongoDB for the SQL Server Pro

Get MongoDB and Driver(s)• Quick download, zero install• Also get your driver (C# for us)

Page 5: MongoDB for the SQL Server Pro

Starting up MongoDB

Page 6: MongoDB for the SQL Server Pro

Using the Console

Page 7: MongoDB for the SQL Server Pro

Using MongoVue

Page 8: MongoDB for the SQL Server Pro

Connecting with MongoVue

Page 9: MongoDB for the SQL Server Pro

Using MongoVue

Page 10: MongoDB for the SQL Server Pro

COMPARING DOCUMENT DATABASES TO RDBMS SYSTEMS

Understanding more..

Page 11: MongoDB for the SQL Server Pro

So which type of NoSQL? CAP…

ConsistencyAvailability

PartitionTolerance

CP = noSQL/columnHadoopBig TableH-baseMemCacheDB(graph)?

CA = SQL/RDBMSSQL Sever / SQL AzureOracleMySQL

AP = noSQL/document or key/valueMongoDBDynamoDBCouchDBCassandraVoldemort

Page 12: MongoDB for the SQL Server Pro

DB Features for MongoDB & SQL Server

primary keys and indexes

queries with models for

sorting / limiting results

a strong typing system

aggregations like SUM(),

COUNT(), etc…

Large object support

Page 13: MongoDB for the SQL Server Pro

DB Features unique to Document DBsCollections, not Tables

Query language, not T-SQL

Idrefs, not Joins

No pre-defined Schema

• Aggregation Framework• Grouping or MapReduce

Aggregations

• No multi-document transactions

No Transactions

No Full-text search

Page 14: MongoDB for the SQL Server Pro

Use 10gen Quick Reference Cards

Page 15: MongoDB for the SQL Server Pro

DB Features of note in MongoDB• BSON supports more complex types (date, geo-spatial, etc…)• Supports dynamic queries via proprietary query language

– Uses “find()” which returns a [lazy] cursor– Multi-key indexes can be created

• Scalability via Replication and Sharding

Page 16: MongoDB for the SQL Server Pro

Why use MongoDB?

• Document-like• Semi-structured• Few Joins• Geospatial

Data Structure

• Large or Huge• Distributed• Unpredictable

Data Volume

Page 17: MongoDB for the SQL Server Pro

MongoDB Scenarios

Document Management

systems

E-commerce (catalog portion

only)

Archiving / event logging

Real time analytics (based

on logging)Gaming Geospatial

Mobile

Page 18: MongoDB for the SQL Server Pro

IMPORTING DATA TO MONGODBDemo

Page 19: MongoDB for the SQL Server Pro

Adding Data

• Data must be in JSON format - converter• “Insert” CREATES a collection if needed

Page 20: MongoDB for the SQL Server Pro

Importing data…using MongoVue

Page 21: MongoDB for the SQL Server Pro

Viewing Collection Data

Page 22: MongoDB for the SQL Server Pro

USING VELOCITY FOR MODELINGDemo

Page 23: MongoDB for the SQL Server Pro

Modeling

Use short names • each name is saved for

each document• can save up to 30%

storage

Keep collections small• Can create non-

default (narrower) key• Document size

maximum is 4 MB

Use GridFS for BLOBs

Page 24: MongoDB for the SQL Server Pro

Com

parin

g…

Page 25: MongoDB for the SQL Server Pro

QUERY MONGODB DATADemo

Page 26: MongoDB for the SQL Server Pro

Using FindFind, Fields, Sort, Count, Skip, Limit, Visualize or Export

Page 27: MongoDB for the SQL Server Pro

Data Visualization

Page 28: MongoDB for the SQL Server Pro

Queries

Page 29: MongoDB for the SQL Server Pro

Queries 2 …

Page 30: MongoDB for the SQL Server Pro

Queries 3…

Page 31: MongoDB for the SQL Server Pro

What is Grouping?

• Similar to T-SQL ‘Group By’• Written in javascript

Page 32: MongoDB for the SQL Server Pro

What about Joins?

No traditional

joins in MongoDB

Can use Arrays

Can use Embedded Documents

Can use DBRef

Can De-normalize schema

Page 33: MongoDB for the SQL Server Pro

About the Aggregation Framework• New in MongoDB 2.2• Layer on top to facilitate easier query-writing

Page 34: MongoDB for the SQL Server Pro

Query Tuning

• Use best indexes– Evaluate use of _id– Add columns to index (specificity)– Multiple columns, most specific first– Can use fully covered indexing (indexOnly:true)– Test to make sure indexes are being used

• Qty scanned s/b same as QTY returned• Use .explain

Page 35: MongoDB for the SQL Server Pro

Understanding Explain

• Query execution detail plan• Review number of scanned objects

Page 36: MongoDB for the SQL Server Pro

ADD INDEXES TO MONGODBUnderstanding more

Page 37: MongoDB for the SQL Server Pro

Modifying Data

Update• alone does a replace

Update w/ $set • does an update

Update w/ $inc • increments

Upserts • must be enabled• then insert if new,

update if existing

Multiple field updates • occur by default

Page 38: MongoDB for the SQL Server Pro

Using Update

Page 39: MongoDB for the SQL Server Pro

USING GRIDFSUnderstanding more…

Page 40: MongoDB for the SQL Server Pro

What is GridFS?

• Used to hold objects larger than 16 MB

Page 41: MongoDB for the SQL Server Pro

CONNECTING TO MONGODB WITH C#Demo

Page 42: MongoDB for the SQL Server Pro

Programming against MongoDB

Page 43: MongoDB for the SQL Server Pro

More Information

• MongoDB– http://www.mongodb.org

• 10gen– http://www.10gen.com/contact– [email protected]

• YouTube videos (from Lynn Langit)– MongoDB Playlist - https://

www.youtube.com/playlist?list=PLCE5902FB1D284880&feature=view_all

• MongoDB LA UG - http://www.meetup.com/Los-Angeles-MongoDB-User-Group

Page 44: MongoDB for the SQL Server Pro

The Changing Data Landscape

NoSQLRDBMS

OtherServices

Page 45: MongoDB for the SQL Server Pro

www.TeachingKidsProgramming.org• Free Courseware ( • Do a Recipe Teach a Kid (Ages 10 ++)• Java or Microsoft SmallBasic

• recipes)

Page 46: MongoDB for the SQL Server Pro

Toward Data Craftsmanship…

Follow me @LynnLangit

RSS my blog www.LynnLangit.com

Hire me• To help build your BI/Big Data solution• To teach your team next gen BI• To learn more about using NoSQL

solutions