Presentation is loading. Please wait.

Presentation is loading. Please wait.

DAPROTA M2 Data modeling service for MongoDB Goran Zugic June 2014.

Similar presentations


Presentation on theme: "DAPROTA M2 Data modeling service for MongoDB Goran Zugic June 2014."— Presentation transcript:

1 DAPROTA M2 Data modeling service for MongoDB Goran Zugic goran.zugic@daprota.com June 2014

2 Agenda Part 1 (20-25 mins) Introduction MongoDB data modeling overview Types of data models What is M2? When to use M2? M2 technology Part 2 (20-25 mins) M2 demonstration Show website Public models Explore Documentation Registration Show some public models Product (embedded) Referenced One-to_many V2 (referenced) Atomic Operation (hybrid) Show M2 features Create one-to-few, one-to-many, and one-to-squillion models (based on patterns from William Zola’s MongoDB blog post) Q & A

3 Part 1

4 Introduction Flexible schema no need to determine and declare structural data elements before inserting data Document-based data model Collections, documents, fields, references Document structure is not enforced what enables mapping of documents to any object (entity) While it is not required, it is recommended to have uniform document structure across single collections.

5 Introduction (cont.) Atomicity There is no concept of transaction in MongoDB All operations that create or change data (e.g., write, update, delete) are atomic at the document level only MongoDB does not support joins. MongoDB is designed to take care of many performance aspects by itself but it leaves to designers and developers to figure out the best possible data model for the specific application patterns.

6 Introduction (cont.) It may come as a surprise to some people, but as Asya Kamsky wrote in her 10 Things You Should Know About Running MongoDB at Scale article, on the High Scalability portal, the biggest impact to performance is “how well the schema design fits with the application needs“. Asya came to this conclusion after having seen hundreds of production deployments. This is a fairly firm statement that proves the importance of data modeling for MongoDB-based systems.10 Things You Should Know About Running MongoDB at Scale

7 Data Modeling Overview MongoDB data models created in M2 includes Collections (analogous to JSON objects, RDBMS tables) Documents (analogous to RDBMS table rows) Fields (analogous to RDBMS table columns) References (analogous to RDBMS foreign keys) Model Collection Document Field Reference

8 Data Modeling Overview (cont.) _id parentId Manual Reference Database A _id parentId Database A Database B DBRef

9 Key Considerations with Data Modeling Read and write operations Document growth Automicity Sharding

10 Types of Data Models There are several types of MongoDB data models you can create: Embedding Model Referencing Model Hybrid Model that combines embedding and referencing models. Embedding model enables de-normalization of data, which means that two or more related pieces of data will be stored in a single document. Frequently it is a choice for “contains” and “one-to-many” relationships between entities (documents). Related data can be fetched with a single query Duplication of data; multi-document changes It is a better choice for atomicity smaller documents; data does not change or does not grow much; data that you usually fetch together; fast reads

11 Types of Data Models (cont.) Referencing model enables normalization of data by storing references between documents to indicate a relationship between the data stored in each document. No duplication of data Only one document change is required to change data No joins. Retrieving data from multiple documents requires multiple queries to be done by an application. It is a better choice for when embedding would result in extensive data duplication (but would not provide a significant read performance advantage) and/or data fragmentation when embedded documents grow; to present more complex “many-to-many” relationships; to model large hierarchical data sets. fast writes Hybrid model is a combination of embedding and referencing model. It is usually used when neither embedding or referencing model is the best choice but their combination makes the most balanced model.

12 Data Modeling Overview (cont.) Collection C1 Doc D2 Doc D1 Collection C1Collection C2 Doc D1 Doc D2 Embedding Model Referencing Model

13 What is M2? M2 is a cloud service for the creation and management of MongoDB data models M2 features include: Management of models and their elements (collections, documents, fields and references) Copying and versioning of models, collections and documents via related Copy utilities Multiple document formats for a collection Full models' view in a JSON-like format (M2 notation) Export/Import Models Public models sharing Models documentation repository Messaging between M2 users

14 When to use M2? Analysis and design are important steps in an overall engineering process of system architecture, design, development and implementation/deployment. M2 is used for a data model (schema) design. Up-to-date data model management with an on-line (cloud) service capability. Educative purposes. Public data model samples based on various design patterns and best practices.

15 When to use M2? (cont.) Models can be documented via documentation stored and managed in M2 documentation repository or referenced via external links. Free service. More plans will be available in near future. Code generation (future releases) Standardizing (based on M2 data models) and automating the writing of data access code (from M2 data models) can save significant developer time and make the resulting code better defined and easier to maintain and to interface with. Model visualisation (future releases)

16 M2 Technology MongoDB Java, Java Servlets, JSP, jQuery Tomcat Red Hat Enterprise Linux

17 Part 2 (M2 Demonstration)

18 How to Access M2? http://www.daprota.com https://m2.daprota.com

19 One-to-Few > db.person.findOne() { _id: ObjectId(‘ABC’), name: ‘John Smith', sin: '123-456-7890', addresses : [ { street: '123 Sesame St', city: ‘Toronto', cc: ‘CA' }, { street: '123 Avenue Q', city: 'New York', cc: 'US' } ] }

20 One-to-Many > db.parts.findOne() { _id : ObjectId('AAA'), partno : '123-aff-456', name : '#4 grommet', qty: 94, price: 3.99 } > db.products.findOne() { _id : ObjectId(‘BBB’), name : 'left-handed smoke shifter', manufacturer : 'Acme Corp', catalog_number: 1234, parts : [ // array of references to Part documents ObjectId('AAA'), // reference to the #4 grommet above ObjectId('F17'), // reference to a different Part ObjectId('D2A'), // etc ]

21 One-to-Squillions > db.hosts.findOne() { _id : ObjectId('AAAB'), name : 'goofy.example.com', ipaddr : '127.66.66.66' } >db.logmsg.findOne() { time : ISODate("2014-03-28T09:42:41.382Z"), message : 'cpu is on fire!', host: ObjectId('AAAB') // Reference to the Host document }

22 Documentation and Books M2 Documentation http://www.daprota.com/doc/m2/m2-documentation.html Data Models (MongoDB Documentation) http://docs.mongodb.org/manual/data-modeling/ MongoDB: The Definitive Guide by Kristina Chodorow (2013) MongoDB: The Definitive GuideKristina Chodorow MongoDB Applied Design Patterns by Rick Copeland (2013) MongoDB Applied Design PatternsRick Copeland MongoDB in Action by Kyle Banker (2011) MongoDB in ActionKyle Banker

23 Q&A

24 Thank you! Goran Zugic goran.zugic@daprota.com http://www.daprota.com https://m2.daprota.com @DaprotaM2 http://goranzugic.wordpress.com/ http://www.goranzugic.com/


Download ppt "DAPROTA M2 Data modeling service for MongoDB Goran Zugic June 2014."

Similar presentations


Ads by Google