mongodb for the sql server pro
TRANSCRIPT
Lynn Langit
MongoDB for the SQL Server Pro
Feb 2013 – For MongoDB LA
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 )
QUICKSTART - SETUP MONGODB Demo
Get MongoDB and Driver(s)• Quick download, zero install• Also get your driver (C# for us)
Starting up MongoDB
Using the Console
Using MongoVue
Connecting with MongoVue
Using MongoVue
COMPARING DOCUMENT DATABASES TO RDBMS SYSTEMS
Understanding more..
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
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
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
Use 10gen Quick Reference Cards
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
Why use MongoDB?
• Document-like• Semi-structured• Few Joins• Geospatial
Data Structure
• Large or Huge• Distributed• Unpredictable
Data Volume
MongoDB Scenarios
Document Management
systems
E-commerce (catalog portion
only)
Archiving / event logging
Real time analytics (based
on logging)Gaming Geospatial
Mobile
IMPORTING DATA TO MONGODBDemo
Adding Data
• Data must be in JSON format - converter• “Insert” CREATES a collection if needed
Importing data…using MongoVue
Viewing Collection Data
USING VELOCITY FOR MODELINGDemo
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
Com
parin
g…
QUERY MONGODB DATADemo
Using FindFind, Fields, Sort, Count, Skip, Limit, Visualize or Export
Data Visualization
Queries
Queries 2 …
Queries 3…
What is Grouping?
• Similar to T-SQL ‘Group By’• Written in javascript
What about Joins?
No traditional
joins in MongoDB
Can use Arrays
Can use Embedded Documents
Can use DBRef
Can De-normalize schema
About the Aggregation Framework• New in MongoDB 2.2• Layer on top to facilitate easier query-writing
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
Understanding Explain
• Query execution detail plan• Review number of scanned objects
ADD INDEXES TO MONGODBUnderstanding more
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
Using Update
USING GRIDFSUnderstanding more…
What is GridFS?
• Used to hold objects larger than 16 MB
CONNECTING TO MONGODB WITH C#Demo
Programming against MongoDB
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
The Changing Data Landscape
NoSQLRDBMS
OtherServices
www.TeachingKidsProgramming.org• Free Courseware ( • Do a Recipe Teach a Kid (Ages 10 ++)• Java or Microsoft SmallBasic
• recipes)
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