Senior Solutions Architect, 10genMark HelmstetterGeneral TechnicalOverview of MongoDB forDev Teams
Agenda• A bit of history…• Introducing MongoDB• MongoDB CRUD Operations• Working with Indexes in MongoDB• Aggregation Fram...
A bit of history…
RDBMS Strengths• Data stored is very compact• Rigid schemas have led to powerful querycapabilities• Data is optimized for ...
It hides what you’re reallydoing
It makes development hardRelationalDatabaseObject RelationalMappingApplicationCode XML Config DB Schema
What do they have incommon?
Enter “Big Data”• Gartner defines it with 3Vs• Volume– Vast amounts of data being collected• Variety– Evolving data– Uncon...
Mapping Big Data to RDBMS• Difficult to store uncontrolled data formats• Scaling via big iron or custom datamarts/partitio...
Introducing MongoDB
Goals• Scale horizontally over commodity systems• Incorporate what works for RDBMSs– Rich data models, ad-hoc queries, ful...
Key Features• Data represented as documents (JSON)– Flexible-schema– Storage/wire format is BSON• Full CRUD support (Creat...
TerminologyRDBMS MongoDBDatabase DatabaseTable CollectionRow Document
Document Oriented, DynamicSchemaname: “jeff”,eyes: “blue”,height: 72,boss: “ben”}{name: “brendan”,aliases: [“el diablo”]}n...
MongoDB is full featuredMongoDB{first_name: „Paul‟,surname: „Miller‟,city: „London‟,location: [45.123,47.232],cars: [{ mod...
Developers are moreproductiveApplicationCodeRelationalDatabaseObject RelationalMappingXML Config DB Schema
Developers are moreproductiveApplicationCodeRelationalDatabaseObject RelationalMappingXML Config DB Schema
MongoDB Scales BetterVs.PriceScalePriceScale
MongoDB CRUDOperations
> use blog> var post = {author: "markh",date: new Date(),title: "My First Blog Post",body: "MongoDB is an open source docu...
> var post = {"_id" : 1,"author" : "markh","title" : "MetLife builds innovative customer service applicationusing MongoDB"...
> db.posts.findOne(){"_id" : ObjectId("517ed472e14b748a44dc0549"),"author" : "markh","date" : ISODate("2013-05-29T20:13:37...
> db.posts.findOne({author:"markh"}){"_id" : ObjectId("517ed472e14b748a44dc0549"),"author" : "markh","date" : ISODate("201...
> db.posts.find({author:"markh"}){"_id" : ObjectId("517ed472e14b748a44dc0549"),"author" : "markh","date" : ISODate("2013-0...
> db.posts.find( { author:"markh" } , { _id:0, author:1 } ){ "author" : "markh" }Projections
// Ranges: $lt, $lte, $gt, $gte> db.posts.find( {author : "markh",date : {$gte : ISODate("2013-01-01T00:00:00.000Z"),$lt :...
// Set: $in, $all, $nin> db.posts.find( {author : "markh",tags : { $all : [ "MongoDB", "Database", "Big Data" ]}}, { title...
// Logical: $or, $and, $not, $nor> db.posts.find( {author : "markh",$or : [{ title : /first/i },{ body : /prototype/i }]} ...
> var post = {author: "markh",date : ISODate("2013-05-29T20:13:37.349Z"),title: "MongoDB is the #1 NoSQL Database",body: "...
> db.posts.update({ _id: 1},{ $set: {slug:"mongodb"} })> db.posts.update({ _id: 1 },{ $unset: {slug:1} })> db.posts.update...
// Array Update Operators// $set, $unset// $push, $pop, $pull, $pullAll, $addToSet> comment = {userid: "fred",date: new Da...
book = {_id: 123456789,title: "MongoDB: The Definitive Guide",available: 1,checkout: [ { by: "joe", date: ISODate("2012-10...
// Delete EVERYTHING in the collection> db.posts.remove()// Delete based on query criteria> db.posts.remove( { _id:3 } )> ...
Working with Indexes inMongoDB
Indexes are the single biggesttunable performance factor inMongoDBAbsent or suboptimal indexesare the most commonavoidable...
// Default (unique) index on _id// create an ascending index on “author”> db.posts.ensureIndex({author:1})> db.posts.find(...
// Arrays of values (multikey indexes)tags: [“MongoDB”, “Database”, “NoSQL”]> db.posts.ensureIndex({ tags: 1 })> db.posts....
// Multiple fields (compound key indexes)> db.posts.ensureIndex({author: 1,date: -1})> db.posts.find( {author : "markh",da...
// Subdocuments{…comments: [ {userid: "fred",date: new Date(),text: "I totally agree!"} ]}db.posts.ensureIndex( { "comment...
> db.pubs.insert( [{name: "Ned Devines",loc : { type : "Point", coordinates : [ -77.410018, 38.9516 ] } },{name: "OSulliva...
> db.pubs.find( { loc : { $near :{ $geometry :{ type : "Point" ,coordinates: [ -77.386164, 38.971088 ] } },$maxDistance : ...
> db.pubs.insert( [{ description: "Irish Pub, serving great Irish beers",menuItems: ["Bangers & Mash", "Fish & Chips"] },{...
> db.pubs.runCommand( "text", { search: "beer",project: { _id: 0 } } ).results[{"score" : 1.5, "obj" : {"description" : "B...
// username in users collection must be uniquedb.users.ensureIndex( { username: 1 }, { unique: true } )Uniqueness Constrai...
// Only documents with comments.userid will be indexeddb.posts.ensureIndex({ "comments.userid": 1 } ,{ sparse: true })// A...
AggregationFramework
Pipeline• Process a stream of documents– Original input is a collection– Final output is a result document• Series of oper...
Pipeline Operators• $match• $project• $group• $unwind• $sort• $limit• $skip
Aggregation FrameworkSQL Statement MongoDB Aggregation StatmentSELECT COUNT(*) AS countFROM ordersdb.orders.aggregate( [{ ...
{title: "The Great Gatsby",pages: 218,language: "English"}{title: "War and Peace",pages: 1440,language: "Russian"}{title: ...
{title: "The Great Gatsby",pages: 218,language: "English"}{title: "War and Peace",pages: 1440,language: "Russian"}{title: ...
{title: "The Great Gatsby",pages: 218,language: "English"}{title: "War and Peace",pages: 1440,language: "Russian"}{title: ...
{title: "The Great Gatsby",pages: 218,language: "English"}{title: "War and Peace",pages: 1440,language: "Russian”}{title: ...
MongoDB Ecosystem
MongoDB EcosystemDriversLibraries /FrameworksApplicationsMonitoringToolsAdminToolsETL ToolsDeploymentToolsIDEsCommunityhtt...
Global Community4,000,000+MongoDB Downloads50,000+Online Education Registrants15,000+MongoDB User Group Members14,000+Mong...
MongoDB is the leading NoSQLDatabase
MongoDB Users
Use CasesContentManagementOperationalIntelligenceHigh VolumeData FeedsE-CommerceUser DataManagementhttp://www.10gen.com/cu...
MongoDB Books
• http://docs.mongodb.org/Online Manual
• http://education.10gen.comFree Online MongoDB Training
DriversCommunity SupportedDriversDriversDrivers for most popularprogramming languages andframeworksJavaPythonPerlRubyHaske...
• CakePHP• CodeIgniter• Fat-Free• Lithium• Symfony 2• TechMVC• Vork• TURBOPY• Grails• Pyramid• DjangoEcosystem – Web Appli...
• Morphia• Doctrine• Kohana• Yii• MongoRecord• ActiveMongo• Comfi• Mandango• MongoDB PHP ODM• Mongoose• Spring Data MongoD...
• Drupal• Locomotive• MongoPress• Calipso• Frameworks– Web frameworks with CMS capabilitites– v7files / VermongoEcosystem ...
• MMS• Munin MongoDB Plugin• Nagios• Ganglia• Zabbix• Scout• Server DensityEcosystem – Monitoring Tools
• Edda• Fang of Mongo• Umongo• MongoExplorer• MongoHub• MongoVision• MongoVUE• mViewer• Opricot• PHPMoAdmin• RockMongo• Ge...
• HTTP Console / Simple REST Interface (built-in)• Sleepy Mongoose (Python)• DrowsyDromedary (Ruby)• MongoDB Rest (Node.js...
• GridFS– Thundergrid– Mongofilesystem• Deployment /Mangagement– puppet-mongodb– chef-mongodb• MongoDB Pagination• Morph• ...
• MongoDB is a full-featured, general purposedatabase• Flexible document data model provides– Greater flexibility– Greater...
• Presentations / Webinars– http://www.10gen.com/presentations• Customer Success Stories– http://www.10gen.com/customers• ...
Questions
Senior Solutions Architect, 10genMark HelmstetterThank You@helmstetter
Webinar: General Technical Overview of MongoDB for Dev Teams
Upcoming SlideShare
Loading in...5
×

Webinar: General Technical Overview of MongoDB for Dev Teams

3,956

Published on

In this talk we will focus on several of the reasons why developers have come to love the richness, flexibility, and ease of use that MongoDB provides. First we will give a brief introduction of MongoDB, comparing and contrasting it to the traditional relational database. Next, we’ll give an overview of the APIs and tools that are part of the MongoDB ecosystem. Then we’ll look at how MongoDB CRUD (Create, Read, Update, Delete) operations work, and also explore query, update, and projection operators. Finally, we will discuss MongoDB indexes and look at some examples of how indexes are used.

Published in: Technology
2 Comments
6 Likes
Statistics
Notes
  • Hi,All am getting following exception when i going to do any operation by using mongoVUE .

    Duplicate element name 'ohm�essagestores3'.
    Type: System.InvalidOperationException
    Stack: at MongoDB.Bson.BsonDocument.Add(BsonElement element)
    at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader, Type nominalType, IBsonSerializationOptions options)
    at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader)
    at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
    at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader, BsonElement& element)
    at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader, Type nominalType, IBsonSerializationOptions options)
    at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader)
    at MongoDB.Bson.Serialization.BsonSerializer.Deserialize(BsonReader bsonReader, Type nominalType, IBsonSerializationOptions options)
    at MongoDB.Driver.Internal.MongoReplyMessage`1.ReadFrom(BsonBuffer buffer, IBsonSerializationOptions serializationOptions)
    at MongoDB.Driver.Internal.MongoConnection.ReceiveMessage[TDocument](BsonBinaryReaderSettings readerSettings, IBsonSerializationOptions serializationOptions)
    at MongoDB.Driver.MongoCursorEnumerator`1.GetReply(MongoConnection connection, MongoRequestMessage message)
    at MongoDB.Driver.MongoCursorEnumerator`1.GetFirst()
    at MongoDB.Driver.MongoCursorEnumerator`1.MoveNext()
    at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
    at MongoDB.Driver.MongoCollection.FindOneAs[TDocument](IMongoQuery query)
    at MongoDB.Driver.MongoCollection`1.FindOne(IMongoQuery query)
    at MongoDB.Driver.MongoDatabase.RunCommandAs(Type commandResultType, IMongoCommand command)
    at MongoDB.Driver.MongoDatabase.RunCommandAs[TCommandResult](IMongoCommand command)
    at MongoDB.Driver.MongoDatabase.RunCommand(IMongoCommand command)
    at MangoUI.MMongo.tg9V3FJKYi2WK5HAULKP(Object , Object )
    at MangoUI.MMongo.ServerStatus()
    at MangoUI.WinInfo.wqAn5dmHF8aM0TVspU4(Object )
    at MangoUI.WinInfo.LoadDetails(MConnection connection, String dbname, MongoTreeItem itemType, String item, String parent, String command)
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Nice introduction to MongoDB, :)
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
3,956
On Slideshare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
0
Comments
2
Likes
6
Embeds 0
No embeds

No notes for slide
  • Magento ER Diagramhttp://www.magento-exchange.com/magento-database/magento-1-4-database-er-diagram/
  • BSON types:stringinteger (32- or 64-bit)double (64-bit IEEE 754 floating point number)date (integer number of milliseconds since the Unix epoch)byte array (binary data)boolean (true and false)null
  • BSON types:stringinteger (32- or 64-bit)double (64-bit IEEE 754 floating point number)date (integer number of milliseconds since the Unix epoch)byte array (binary data)boolean (true and false)null
  • These are called targeted modifications
  • So it’s imperative we understand them
  • Indexes can be costly if you have too manysoooo....
  • GeoJSON is an open format (based on the JSON standard) for encoding a variety of geographic data structures. MongoDB supports the following GeoJSON objects:PointLineStringPolygon
  • $geoWithin - GeoJSON Objects Bounded by a Polygon$geoIntersects operator queries for locations that intersect a specified GeoJSON object.
  • unique applies a uniqueness constant on duplicate values.dropDups will force the server to create a unique index by only keeping the first document found in natural order with a value and dropping all other documents with that value.dropDups will likely result in data loss!!!TODO: Maybe add a red exclamation point for dropDups.
  • MongoDB doesn't enforce a schema – documents are not required to have the same fields.Sparse indexes only contain entries for documents that have the indexed field.Without sparse, documents without field 'a' have a null entry in the index for that field.With sparse a unique constraint can be applied to a field not shared by all documents. Otherwise multiple 'null' values violate the unique constraint.XXX: Is there a visual that makes sense here?
  • MongoDB uses BSON as the data storage and network transfer format for “documents”.
  • Webinar: General Technical Overview of MongoDB for Dev Teams

    1. 1. Senior Solutions Architect, 10genMark HelmstetterGeneral TechnicalOverview of MongoDB forDev Teams
    2. 2. Agenda• A bit of history…• Introducing MongoDB• MongoDB CRUD Operations• Working with Indexes in MongoDB• Aggregation Framework• MongoDB Ecosystem
    3. 3. A bit of history…
    4. 4. RDBMS Strengths• Data stored is very compact• Rigid schemas have led to powerful querycapabilities• Data is optimized for joins and storage• Robust ecosystem of tools, libraries, integrations• 40 years old!
    5. 5. It hides what you’re reallydoing
    6. 6. It makes development hardRelationalDatabaseObject RelationalMappingApplicationCode XML Config DB Schema
    7. 7. What do they have incommon?
    8. 8. Enter “Big Data”• Gartner defines it with 3Vs• Volume– Vast amounts of data being collected• Variety– Evolving data– Uncontrolled formats, no single schema– Unknown at design time• Velocity– Inbound data speed– Fast read/write operations– Low latency
    9. 9. Mapping Big Data to RDBMS• Difficult to store uncontrolled data formats• Scaling via big iron or custom datamarts/partitioning schemes• Schema must be known at design time• Impedance mismatch with agile developmentand deployment techniques• Doesn‟t map well to native language constructs
    10. 10. Introducing MongoDB
    11. 11. Goals• Scale horizontally over commodity systems• Incorporate what works for RDBMSs– Rich data models, ad-hoc queries, full indexes• Drop what doesn‟t work well– Complex schemas, multi-row transactions, complex joins• Do not homogenize APIs• Match agile development and deploymentworkflows
    12. 12. Key Features• Data represented as documents (JSON)– Flexible-schema– Storage/wire format is BSON• Full CRUD support (Create, Read, Update, Delete)– Atomic in-place updates– Ad-hoc queries: Equality, RegEx, Ranges,Geospatial,Text• Secondary indexes• Replication – redundancy, failover• Sharding – partitioning for read/write scalability
    13. 13. TerminologyRDBMS MongoDBDatabase DatabaseTable CollectionRow Document
    14. 14. Document Oriented, DynamicSchemaname: “jeff”,eyes: “blue”,height: 72,boss: “ben”}{name: “brendan”,aliases: [“el diablo”]}name: “ben”,hat: ”yes”}{name: “matt”,pizza: “DiGiorno”,height: 72,boss: 555.555.1212}{name: “will”,eyes: “blue”,birthplace: “NY”,aliases: [“bill”, “laciacco”],gender: ”???”,boss: ”ben”}
    15. 15. MongoDB is full featuredMongoDB{first_name: „Paul‟,surname: „Miller‟,city: „London‟,location: [45.123,47.232],cars: [{ model: „Bently‟,year: 1973,value: 100000, … },{ model: „Rolls Royce‟,year: 1965,value: 330000, … }}}Rich Queries• Find Paul’s cars• Find everybody who owns a car builtbetween 1970 and 1980Geospatial • Find all of the car owners in LondonText Search• Find all the cars described as havingleather seatsAggregation• What’s the average value of Paul’s carcollectionMap Reduce• What is the ownership pattern of colorsby geography over time? (is purpletrending up in China?)
    16. 16. Developers are moreproductiveApplicationCodeRelationalDatabaseObject RelationalMappingXML Config DB Schema
    17. 17. Developers are moreproductiveApplicationCodeRelationalDatabaseObject RelationalMappingXML Config DB Schema
    18. 18. MongoDB Scales BetterVs.PriceScalePriceScale
    19. 19. MongoDB CRUDOperations
    20. 20. > use blog> var post = {author: "markh",date: new Date(),title: "My First Blog Post",body: "MongoDB is an open source document-oriented databasesystem developed and supported by 10gen.",tags: ["MongoDB"]}> db.posts.insert(post)Create – insert()
    21. 21. > var post = {"_id" : 1,"author" : "markh","title" : "MetLife builds innovative customer service applicationusing MongoDB","body" : "MetLife built a working prototype in two weeks andwas live in U.S. call centers in 90 days.","date" : ISODate("2013-05-07T00:00:00.000Z"),"tags" : ["MongoDB", "Database", "Big Data"]}> db.posts.update({ _id:1 }, post, { upsert : true })// upsert option with <query> argument on _id -- same as save()Upsert
    22. 22. > db.posts.findOne(){"_id" : ObjectId("517ed472e14b748a44dc0549"),"author" : "markh","date" : ISODate("2013-05-29T20:13:37.349Z"),"title" : "My First Blog Post","body" : "MongoDB is an open source document-orienteddatabase system developed and supported by 10gen.","tags" : ["MongoDB"]}// _id is unique but can be anything you likeRead – findOne()
    23. 23. > db.posts.findOne({author:"markh"}){"_id" : ObjectId("517ed472e14b748a44dc0549"),"author" : "markh","date" : ISODate("2013-05-29T20:13:37.349Z"),"title" : "My First Blog Post","body" : "MongoDB is an open source document-orienteddatabase system developed and supported by 10gen.","tags" : ["MongoDB"]}Read – findOne()
    24. 24. > db.posts.find({author:"markh"}){"_id" : ObjectId("517ed472e14b748a44dc0549"),"author" : "markh","date" : ISODate("2013-05-29T20:13:37.349Z"),"title" : "My First Blog Post","body" : "MongoDB is an open source document-orienteddatabase system developed and supported by 10gen.","tags" : ["MongoDB"]}…Read – find()
    25. 25. > db.posts.find( { author:"markh" } , { _id:0, author:1 } ){ "author" : "markh" }Projections
    26. 26. // Ranges: $lt, $lte, $gt, $gte> db.posts.find( {author : "markh",date : {$gte : ISODate("2013-01-01T00:00:00.000Z"),$lt : ISODate("2013-05-10T02:50:27.874Z")}}){ "title" : "MetLife builds innovative customer service applicationusing MongoDB","date" : ISODate("2013-05-07T00:00:00Z") }Range Query Operators
    27. 27. // Set: $in, $all, $nin> db.posts.find( {author : "markh",tags : { $all : [ "MongoDB", "Database", "Big Data" ]}}, { title:1 }){"_id" : 1,"title" : "MetLife builds innovative customer service applicationusing MongoDB"}Set Query Operators
    28. 28. // Logical: $or, $and, $not, $nor> db.posts.find( {author : "markh",$or : [{ title : /first/i },{ body : /prototype/i }]} ).count()2Logical Query Operators
    29. 29. > var post = {author: "markh",date : ISODate("2013-05-29T20:13:37.349Z"),title: "MongoDB is the #1 NoSQL Database",body: "MongoDB is an open source document-oriented databasesystem developed and supported by 10gen.",tags: ["MongoDB"]}> db.posts.update({ _id:ObjectId("517ed472e14b748a44dc0549") },post)Update
    30. 30. > db.posts.update({ _id: 1},{ $set: {slug:"mongodb"} })> db.posts.update({ _id: 1 },{ $unset: {slug:1} })> db.posts.update({ _id: 1 },{ $inc: {revision:1} })Update Operators
    31. 31. // Array Update Operators// $set, $unset// $push, $pop, $pull, $pullAll, $addToSet> comment = {userid: "fred",date: new Date(),text: "I totally agree!"}> db.posts.update( { _id: 1 }, {$push: {comments: comment}});Array Update Operators
    32. 32. book = {_id: 123456789,title: "MongoDB: The Definitive Guide",available: 1,checkout: [ { by: "joe", date: ISODate("2012-10-15") } ]}> db.books.findAndModify ( {query: { _id: 123456789, available: { $gt: 0 } },update: {$inc: { available: -1 },$push: { checkout: { by: "abc", date: new Date() } } }} )findAndModify
    33. 33. // Delete EVERYTHING in the collection> db.posts.remove()// Delete based on query criteria> db.posts.remove( { _id:3 } )> db.posts.remove( { author:"john" } )// Only delete one document using "justOne" option> db.posts.remove( { author:"john" }, true )Delete
    34. 34. Working with Indexes inMongoDB
    35. 35. Indexes are the single biggesttunable performance factor inMongoDBAbsent or suboptimal indexesare the most commonavoidable MongoDBperformance problem.
    36. 36. // Default (unique) index on _id// create an ascending index on “author”> db.posts.ensureIndex({author:1})> db.posts.find({author:"markh"})Indexing a single value
    37. 37. // Arrays of values (multikey indexes)tags: [“MongoDB”, “Database”, “NoSQL”]> db.posts.ensureIndex({ tags: 1 })> db.posts.find({tags: "MongoDB"})Indexing Array Elements
    38. 38. // Multiple fields (compound key indexes)> db.posts.ensureIndex({author: 1,date: -1})> db.posts.find( {author : "markh",date : {$gte : ISODate("2013-01-01T00:00:00.000Z"),$lt : ISODate("2013-05-10T02:50:27.874Z")}})Compound Indexes
    39. 39. // Subdocuments{…comments: [ {userid: "fred",date: new Date(),text: "I totally agree!"} ]}db.posts.ensureIndex( { "comments.userid": 1 } )Indexing Subdocuments
    40. 40. > db.pubs.insert( [{name: "Ned Devines",loc : { type : "Point", coordinates : [ -77.410018, 38.9516 ] } },{name: "OSullivans",loc : { type : "Point", coordinates : [ -77.386329, 38.970754 ] } },{name: "Old Brogue",loc : { type : "Point", coordinates : [ -77.29067, 38.998542 ] } },{name: "Finnegans",loc : { type : "Point", coordinates : [ -77.395275, 38.952734 ] } }])> db.pubs.ensureIndex( { loc : "2dsphere" }Geospatial Indexes
    41. 41. > db.pubs.find( { loc : { $near :{ $geometry :{ type : "Point" ,coordinates: [ -77.386164, 38.971088 ] } },$maxDistance : 500} } ){ "name" : "OSullivans","loc" : { "type" : "Point", "coordinates" : [ -77.386329, 38.970754 ] } }Geospatial Indexes
    42. 42. > db.pubs.insert( [{ description: "Irish Pub, serving great Irish beers",menuItems: ["Bangers & Mash", "Fish & Chips"] },{ description:"Sports bar and restaurant",menuItems: [ "Burgers", "Wings", "Pizza"] },{ description:"Beer joint",menuItems: [ "Belgian Beers", "Micro Brews", "Cask Ales"] }])> db.pubs.ensureIndex( {description: "text",menuItems: "text"} )Text Indexes
    43. 43. > db.pubs.runCommand( "text", { search: "beer",project: { _id: 0 } } ).results[{"score" : 1.5, "obj" : {"description" : "Beer joint","menuItems" : ["Belgian Beers", "Micro Brews", "Cask Ales"]} },{"score" : 0.5833333333333334, "obj" : {"description" : "Irish Pub, serving great Irish beers","menuItems" : ["Bangers & Mash", "Fish & Chips", "Sheperds Pie"]} } ]Text Indexes
    44. 44. // username in users collection must be uniquedb.users.ensureIndex( { username: 1 }, { unique: true } )Uniqueness Constraints
    45. 45. // Only documents with comments.userid will be indexeddb.posts.ensureIndex({ "comments.userid": 1 } ,{ sparse: true })// Allow multiple documents to not have a sku fielddb.products.ensureIndex( {sku: 1}, {unique: true, sparse: true} )Sparse Indexes
    46. 46. AggregationFramework
    47. 47. Pipeline• Process a stream of documents– Original input is a collection– Final output is a result document• Series of operators– Filter or transform data– Input/output chainps ax | grep mongod | head -n 1
    48. 48. Pipeline Operators• $match• $project• $group• $unwind• $sort• $limit• $skip
    49. 49. Aggregation FrameworkSQL Statement MongoDB Aggregation StatmentSELECT COUNT(*) AS countFROM ordersdb.orders.aggregate( [{ $group: { _id: null,count: { $sum: 1 } } }] )SELECT SUM(price) AS totalFROM ordersdb.orders.aggregate( [{ $group: { _id: null,total: { $sum: "$price" } } }] )SELECT cust_id, SUM(price) AS totalFROM ordersGROUP BY cust_iddb.orders.aggregate( [{ $group: { _id: "$cust_id",total: { $sum: "$price" } } }] )SELECT cust_id, SUM(price) as totalFROM ordersWHERE status = AGROUP BY cust_iddb.orders.aggregate( [{ $match: { status: A } },{ $group: { _id: "$cust_id",total: { $sum: "$price" } } }] )
    50. 50. {title: "The Great Gatsby",pages: 218,language: "English"}{title: "War and Peace",pages: 1440,language: "Russian"}{title: "Atlas Shrugged",pages: 1088,language: "English"}Matching Field Values{ $match: {language: "Russian"}}{title: "War and Peace",pages: 1440,language: "Russian"}
    51. 51. {title: "The Great Gatsby",pages: 218,language: "English"}{title: "War and Peace",pages: 1440,language: "Russian"}{title: "Atlas Shrugged",pages: 1088,language: "English"}Matching with QueryOperators{ $match: {pages: { $gt: 1000 }}}{title: "War and Peace",pages: 1440,language: "Russian"}{title: "Atlas Shrugged",pages: 1088,language: "English"}
    52. 52. {title: "The Great Gatsby",pages: 218,language: "English"}{title: "War and Peace",pages: 1440,language: "Russian"}{title: "Atlas Shrugged",pages: 1088,language: "English"}Calculating an Average{ $group: {_id: "$language",avgPages: { $avg:"$pages" }}}{_id: "Russian",avgPages: 1440}{_id: "English",avgPages: 653}
    53. 53. {title: "The Great Gatsby",pages: 218,language: "English"}{title: "War and Peace",pages: 1440,language: "Russian”}{title: "Atlas Shrugged",pages: 1088,language: "English"}Summating Fields andCounting{ $group: {_id: "$language",numTitles: { $sum: 1 },sumPages: { $sum: "$pages" }}}{_id: "Russian",numTitles: 1,sumPages: 1440}{_id: "English",numTitles: 2,sumPages: 1306}
    54. 54. MongoDB Ecosystem
    55. 55. MongoDB EcosystemDriversLibraries /FrameworksApplicationsMonitoringToolsAdminToolsETL ToolsDeploymentToolsIDEsCommunityhttp://docs.mongodb.org/ecosystem/
    56. 56. Global Community4,000,000+MongoDB Downloads50,000+Online Education Registrants15,000+MongoDB User Group Members14,000+MongoDB Monitoring Service (MMS) Users10,000+Annual MongoDB DaysAttendees
    57. 57. MongoDB is the leading NoSQLDatabase
    58. 58. MongoDB Users
    59. 59. Use CasesContentManagementOperationalIntelligenceHigh VolumeData FeedsE-CommerceUser DataManagementhttp://www.10gen.com/customers
    60. 60. MongoDB Books
    61. 61. • http://docs.mongodb.org/Online Manual
    62. 62. • http://education.10gen.comFree Online MongoDB Training
    63. 63. DriversCommunity SupportedDriversDriversDrivers for most popularprogramming languages andframeworksJavaPythonPerlRubyHaskellJavaScriptPowerShellPrologRacket
    64. 64. • CakePHP• CodeIgniter• Fat-Free• Lithium• Symfony 2• TechMVC• Vork• TURBOPY• Grails• Pyramid• DjangoEcosystem – Web ApplicationFrameworks
    65. 65. • Morphia• Doctrine• Kohana• Yii• MongoRecord• ActiveMongo• Comfi• Mandango• MongoDB PHP ODM• Mongoose• Spring Data MongoDB• Hibernate OGM• MongoEngine• SalatEcosystem – ODM
    66. 66. • Drupal• Locomotive• MongoPress• Calipso• Frameworks– Web frameworks with CMS capabilitites– v7files / VermongoEcosystem – CMS
    67. 67. • MMS• Munin MongoDB Plugin• Nagios• Ganglia• Zabbix• Scout• Server DensityEcosystem – Monitoring Tools
    68. 68. • Edda• Fang of Mongo• Umongo• MongoExplorer• MongoHub• MongoVision• MongoVUE• mViewer• Opricot• PHPMoAdmin• RockMongo• Genghis• Meclipse• Humongous• MongoDB ODAplugin for BIRT• MonadManagementfor MongoDBEcosystem – Admin UIs
    69. 69. • HTTP Console / Simple REST Interface (built-in)• Sleepy Mongoose (Python)• DrowsyDromedary (Ruby)• MongoDB Rest (Node.js)• MongoDB Java REST ServerEcosystem – HTTP/RESTInterfaces
    70. 70. • GridFS– Thundergrid– Mongofilesystem• Deployment /Mangagement– puppet-mongodb– chef-mongodb• MongoDB Pagination• Morph• Mongodloid• SimpleMongoPhp• Mongo-Queue-PHPEcosystem – Miscelenia
    71. 71. • MongoDB is a full-featured, general purposedatabase• Flexible document data model provides– Greater flexibility– Greater agility• MongoDB is built for "Big Data"• Healthy, strong, and growing ecosystem /communityConclusion
    72. 72. • Presentations / Webinars– http://www.10gen.com/presentations• Customer Success Stories– http://www.10gen.com/customers• MongoDB Documentation– http://docs.mongodb.org/• Community– https://groups.google.com/group/mongodb-user– http://stackoverflow.com/questions/tagged/mongodbResources
    73. 73. Questions
    74. 74. Senior Solutions Architect, 10genMark HelmstetterThank You@helmstetter

    ×