1 / 23

Overview

Overview. Document oriented , not table / row oriented Collection of binary JSON (BSON) documents Schemaless No relations or transactions native in database Scalable and high-performance Full index support Written in C++ Servers for all major platforms

tangia
Download Presentation

Overview

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Overview • Document oriented, nottable/roworiented • Collection of binary JSON (BSON) documents • Schemaless • No relations or transactions native in database • Scalableandhigh-performance • Full index support • Written in C++ • Servers forall major platforms • Drivers forall major development environments • Free and open-source, but also commercial support

  2. NoSQL “Next Generation Databases mostly addressing some of the points: being non-relational, distributed, open-source and horizontally scalable”

  3. BASE As a contrast to ACID • BasicallyAvailablemost data is available most of the time • Soft statethe DB provides a relaxed view of data in terms of consistency • Eventually consistentdata is eventually copied to all applicable nodes, but there is no requirement for all nodes to have identical copies of any given data all the time

  4. Use cases • High performance andscalableapplications • Most web applicationswhereyouwouldpreviouslyuse SQL Do notusefor: • Transaction-criticalapplications

  5. Use cases

  6. Performance • inserting 50,000 independent objects using NoRM for MongoDB and LINQ to SQL for SQL Server 2008 • five concurrent clients • Queries on indexedidfields

  7. TerminologyandConcepts

  8. BSON • Binary JSON • Binary encoded serialization of JSON-like documents • Like JSON, BSON supports the embedding of documents and arrays within other documents and arrays. BSON also contains extensions that allow representation of data types that are not part of the JSON spec. For example, BSON has a Date type and a BinData type. • The driver performs translation from the language’s “domain object” data representation to BSON, and back

  9. Embeddingdocuments • Nesting of objects and arrays inside a BSON document • For a “contains” type of relationship • Retrieve entire document with one call • { _id: ObjectId(‘12345‘), author: 'joe', created : new Date('03/28/2009'), title : 'Yetanother blog post', text : 'Here is the text...', tags : [ 'example', 'joe' ], comments : [ { author: 'jim', comment: 'I disagree' }, { author: 'nancy', comment: 'Good post' } ] }

  10. Linkingdocuments • “application-level relations” • Whereembeddingwouldcauseduplication of data • { _id: ObjectId(‘12345‘), • author: 'joe', • created : new Date('03/28/2009'), • title : 'Yetanother blog post', • text : 'Here is the text...', • tags : [ 'example', 'joe‘ ] • } • { author: 'jim', • post_id: ObjectId(‘12345‘), • comment: 'I disagree‘ • } • { author: 'nancy', • post_id: ObjectId(‘12345‘), • comment: 'Good post' • }

  11. Querying • Queries return a cursor, which can be iterated to retrieve results • Query optimizer executes new plans in parallel • Queries are expressed as BSON documents which indicate a query pattern db.users.find({'last_name': 'Smith'}) // retrievessn field fordocumentswherelast_name == 'Smith': db.users.find({last_name: 'Smith'}, {'ssn': 1}); // retrieveallfields *except* the thumbnail field, foralldocuments: db.users.find({}, {thumbnail:0}); // retrieveall users order bylast_name: db.users.find({}).sort({last_name: 1}); // skip and limit: db.users.find().skip(20).limit(10);

  12. Advanced querying { name: "Joe", address: { city: "San Francisco", state: "CA" } , likes: [ 'scuba', 'math', 'literature' ] } // field in sub-document: db.persons.find( { "address.state" : "CA" } ) // find in array: db.persons.find( { likes : "math" } ) // regularexpressions: db.persons.find( { name : /acme.*corp/i } ); // javascript where clause: db.persons.find("this.name != 'Joe'"); // check forexistence of field: db.persons.find( { address: { $exists : true } } ); • Aggregatequerieslikegroupby, count, distinct; onlyavailablefor single instances

  13. Map/Reduce

  14. Inserting& updating • Supports bulk inserts • Default saves are upserts • In place updating • Atomic transactions for single documents • Server side JavaScriptexecution

  15. C# Driver // Opening a server connection; usesconnection pool so no needfordisconnect var connectionString = "mongodb://localhost/?safe=true"; var server = MongoServer.Create(connectionString); // Get a referenceto the “test” database vardatabase = server.GetDatabase("test"); // Get a referenceto the “entities” collection varcollection = database.GetCollection<Entity>("entities"); // Insertinganentity; willset the Idifnecessary varentity = newEntity { Name = "Tom" }; collection.Insert(entity); varid = entity.Id; // Retrieving a single document on primarykey var query = Query.EQ("_id", id); varentity = collection.FindOne(query); // Savinganentity (performsupsert) entity.Name = "Dick"; collection.Save(entity); // Updating anentitydirectly varupdate = Update.Set("Name", "Harry"); collection.Update(query, update); // Delete from database collection.Remove(query);

  16. Indexes • Unique index on primarykey (_idfield) • Create index fromapplication code (ensureIndex) • Index on embeddeddocumentsandfields • Index on array fields (multikey index) • Unique andsparse index • Geospatial index • TTL index • No native full textindexing

  17. Replication • A replica set is a cluster of mongodinstances • 2-12 instances; one is primary • Writesare directedtoprimary • Secondaryinstancesreplicatefromprimaryasynchronously • Automatedfailover; whenprimaryfails a secondarywillbeelected the new primary

  18. Auto-sharding • Partitions data acrossshards • Any BSON document resides on onlyoneshard • Increaseswritecapacityandtotal data size • Data automaticallydistributed • Shardingtransparenttoapplicationlayer • Partitioningbased on client-definedshardkey • Goodshardkeys are highlydistributed in valueandwrite operations • Shardingrequiresconfig servers (minimal 3) tomaintainmetadata

  19. Large deployment

  20. GridFS • Large blob data, limitedonlyby storage space • BSON documents max 16 MB • Supports manythousands of files • Supports oftenchanging files

  21. Security

  22. Adoption

More Related