MongoDB for the .NET Developer            Lynn Langit           Data Wrangler                           May 2012 – For NoS...
What We’ll Cover•   What•   Why•   When and Where•   How•   How much
Section OneMONGODB BASICS
What is MongoDB?
What is MongoDB?•   Open source NoSQL database•   Document-oriented•   Stores JSON-like documents (dynamic schemas)•   Inc...
ActivityONLINE TUTORIAL - TRY IT OUT
Why use MongoDB?• When your source data is ‘document-like’  – i.e. Document Management systems  – E-commerce (catalog port...
So which type of NoSQL? Back to CAP…                                                       CA = SQL/RDBMSCP = noSQL/column...
Relational & Document Models• Both systems support…  – primary keys and indexes  – queries with models for sorting / limit...
Document Model Databases have…•   No Tables•   No T-SQL•   No Joins•   No pre-defined Schema•   Aggregations via Grouping ...
Unique to MongoDB• BSON supports more complex types (date, geo-spatial, etc…)• Supports dynamic queries via proprietary qu...
Use 10gen Quick Reference Cards
Get MongoDB and Driver(s)• Quick download, zero install• Also get your driver (C# for us)
ActivitySETUP MONGODB
Using the console
Using MongoVue
Connecting with MongoVue
Using MongoVue
Adding Data• Data must be in JSON format - converter• “Insert” CREATES a collection if needed
Importing data…using MongoVue
ActivityADDING DATA TO MONGODB
Viewing Collection Data
Using FindFind, Fields, Sort, Count, Skip, Limit, Visualize or Export
Data Visualization
Understanding Explain• Query execution detail plan• Review number of scanned objects
Modifying Data• Update – alone does a replace• Update w/ $set – does an update• Update w/ $inc – increments• Upserts – mus...
Using Update
Section TwoMONGODB PROGRAMMING
Comparing…
ActivityQUERY MONGODB DATA
Queries
Queries more
Queries 3…
What is Grouping?• Similar to T-SQL ‘Group By’• Written in javascript
MapReduce in MongoDB• Written in JavaScript• Map  – Transforms input and emits key => value pairs  – These K/V pairs will ...
Using MapReduce• Example: find the 2 closest cities in each  country, except in United States• Using SQL Server (T-SQL) vs...
MapReduce in MongoVue - I
MapReduce in MongoVue - II
ActivityMAPREDUCE IN MONGODB
What about Joins?•   No traditional joins in MongoDB•   Can use Arrays•   Can use Embedded Documents•   Can use DBRef•   C...
Modeling• Use short names – each name is saved for  each document, can save up to 30% storage• Keep collections small• Doc...
How to Model• Using Velocity
Query Tuning• Use best indexes  – Non _id  – Add columns to index (specificity)  – Mulitple columns, most specific first  ...
What is GridFS?• Used to hold objects larger than 4 MB
ActivityUSING GRIDFS
Programming against MongoDB
ActivityCONNECTING TO MONGODB WITHC#
More Information• MongoDB   – http://www.mongodb.org• 10gen   – http://www.10gen.com/contact   – info@10gen.com• YouTube v...
The Changing Data Landscape                               Other                              ServicesRDBMS           NoSQL
Toward Data Craftsmanship…                Follow me @LynnLangit                     RSS my blog                  www.LynnL...
MongoDB for the .NET Developer
MongoDB for the .NET Developer
MongoDB for the .NET Developer
Upcoming SlideShare
Loading in...5
×

MongoDB for the .NET Developer

6,061

Published on

Published in: Technology
0 Comments
9 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
6,061
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
157
Comments
0
Likes
9
Embeds 0
No embeds

No notes for slide
  • http://en.wikipedia.org/wiki/MongoDB
  • Source - http://www.10gen.com/what-is-mongodb
  • http://www.mongodb.org/display/DOCS/Use+Cases
  • http://amitpiplani.blogspot.com/2010/05/u-pick-2-selection-for-nosql-providers.html
  • http://www.10gen.com/reference
  • http://www.mongodb.org/downloadshttps://github.com/mongodb/mongo-csharp-driver/downloads
  • https://www.youtube.com/watch?v=k2YFy5IQu1M
  • http://www.mongovue.com/
  • Free conversion (CSV to JSON) - http://www.cparker15.com/code/utilities/csv-to-json/
  • http://www.mongovue.com/2010/06/29/find/
  • http://www.mongovue.com/2010/09/14/updating-collections/
  • http://rickosborne.org/download/SQL-to-MongoDB.pdf
  • http://api.mongodb.org/wiki/current/Aggregation.html
  • http://blog.mongovue.com/2010/11/03/yet-another-mongodb-map-reduce-tutorial/
  • http://www.mongovue.com/2010/11/03/yet-another-mongodb-map-reduce-tutorial/Link to download source data - http://www.geobytes.com/freeservices.htm
  • https://www.youtube.com/watch?v=au-4aYQWrjQ
  • http://learnmongo.com/posts/getting-started-with-mongodb-gridfs/Example: http://stackoverflow.com/questions/4988436/mongodb-gridfs-with-c-how-to-store-files-such-as-images/10645816#10645816Default chunk size is 256kbDb.fs.filesFs.chunkUpload.date.date()
  • http://www.youtube.com/watch?v=NCp4n6xWw68
  • https://www.youtube.com/watch?v=NCp4n6xWw68
  • Lynn
  • MongoDB for the .NET Developer

    1. 1. MongoDB for the .NET Developer Lynn Langit Data Wrangler May 2012 – For NoSQL class
    2. 2. What We’ll Cover• What• Why• When and Where• How• How much
    3. 3. Section OneMONGODB BASICS
    4. 4. What is MongoDB?
    5. 5. 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 )
    6. 6. ActivityONLINE TUTORIAL - TRY IT OUT
    7. 7. Why use MongoDB?• When your source data is ‘document-like’ – i.e. Document Management systems – E-commerce (catalog portion only) – When your source data doesn’t require joins• Archiving / event logging – Real time analytics (based on logging)• Gaming – Geospatial – Mobile
    8. 8. So which type of NoSQL? Back to CAP… CA = SQL/RDBMSCP = noSQL/column SQL Sever / SQLHadoop AzureBig Table OracleH-base MySQLMemCacheDB(graph)? Consistency Availability AP = noSQL/document or key/value MongoDB Partitioning DynamoDB CouchDB Cassandra Voldemort
    9. 9. Relational & Document Models• Both systems support… – primary keys and indexes – queries with models for sorting / limiting results – a strong typing system – aggregations like SUM(), COUNT(), etc…
    10. 10. Document Model Databases have…• No Tables• No T-SQL• No Joins• No pre-defined Schema• Aggregations via Grouping or MapReduce• No Transactions• No Full-text search
    11. 11. Unique to MongoDB• BSON supports more complex types (date, geo-spatial, etc…)• Supports dynamic queries via proprietary query language – Uses “find()” which returns a *lazy+ cursor – Ex., “Db.posts.find().sort(,date:-1}).limit(10);” – Multi-key indexes can be created
    12. 12. Use 10gen Quick Reference Cards
    13. 13. Get MongoDB and Driver(s)• Quick download, zero install• Also get your driver (C# for us)
    14. 14. ActivitySETUP MONGODB
    15. 15. Starting up MongoDB
    16. 16. Using the console
    17. 17. Using MongoVue
    18. 18. Connecting with MongoVue
    19. 19. Using MongoVue
    20. 20. Adding Data• Data must be in JSON format - converter• “Insert” CREATES a collection if needed
    21. 21. Importing data…using MongoVue
    22. 22. ActivityADDING DATA TO MONGODB
    23. 23. Viewing Collection Data
    24. 24. Using FindFind, Fields, Sort, Count, Skip, Limit, Visualize or Export
    25. 25. Data Visualization
    26. 26. Understanding Explain• Query execution detail plan• Review number of scanned objects
    27. 27. 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
    28. 28. Using Update
    29. 29. Section TwoMONGODB PROGRAMMING
    30. 30. Comparing…
    31. 31. ActivityQUERY MONGODB DATA
    32. 32. Queries
    33. 33. Queries more
    34. 34. Queries 3…
    35. 35. What is Grouping?• Similar to T-SQL ‘Group By’• Written in javascript
    36. 36. MapReduce in MongoDB• Written in JavaScript• Map – Transforms input and emits key => value pairs – These K/V pairs will be reduced• Reduce – Transform key/values to output via aggregation• Finalize (optional)• Filters (optional)
    37. 37. Using MapReduce• Example: find the 2 closest cities in each country, except in United States• Using SQL Server (T-SQL) vs.• Using MongoDB (MapReduce)
    38. 38. MapReduce in MongoVue - I
    39. 39. MapReduce in MongoVue - II
    40. 40. ActivityMAPREDUCE IN MONGODB
    41. 41. What about Joins?• No traditional joins in MongoDB• Can use Arrays• Can use Embedded Documents• Can use DBRef• Can De-normalize schema
    42. 42. Modeling• Use short names – each name is saved for each document, can save up to 30% storage• Keep collections small• Document size maximum is 4 MB• Use GridFS for BLOBs
    43. 43. How to Model• Using Velocity
    44. 44. Query Tuning• Use best indexes – Non _id – Add columns to index (specificity) – Mulitple columns, most specific first – Test to make sure indexes are being used• Qty scanned s/b same as QTY returned• Use .explain
    45. 45. ActivityADD INDEXES TO MONGODB
    46. 46. What is GridFS?• Used to hold objects larger than 4 MB
    47. 47. ActivityUSING GRIDFS
    48. 48. Programming against MongoDB
    49. 49. ActivityCONNECTING TO MONGODB WITHC#
    50. 50. More Information• MongoDB – http://www.mongodb.org• 10gen – http://www.10gen.com/contact – info@10gen.com• 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
    51. 51. The Changing Data Landscape Other ServicesRDBMS NoSQL
    52. 52. • recipes)www.TeachingKidsProgramming.org• Free Courseware (• Do a Recipe  Teach a Kid (Ages 10 ++)• Java or Microsoft SmallBasic 
    53. 53. 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

    ×