O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

MongoDB Data Modeling

Book Description

Focus on data usage and better design schemas with the help of MongoDB

In Detail

This book covers the basic concepts in data modeling and also provides you with the tools to design better schemas. With a focus on data usage, this book will cover how queries and indexes can influence the way we design schemas, with thorough examples and detailed code.

The book begins with a brief discussion of data models, drawing a parallel between relational databases, NoSQL, and consequently MongoDB. Next, the book explains the most basic MongoDB concepts, such as read and write operations, indexing, and how to design schemas by knowing how applications will use the data. Finally, we will talk about best practices that will help you optimize and manage your database, presenting you with a real-life example of data modeling on a real-time logging analytics application.

What You Will Learn

  • Optimize your models based on priorities
  • Discover the schemaless document-oriented database design
  • Improve the process of querying a document with the help of indexing
  • Set up a sharded environment with replication
  • Configure the read preference in accordance with your application's requirements
  • Create effective indexes that will fit your application needs
  • Understand how to analyze the performance of your queries to avoid performance issues

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Table of Contents

  1. MongoDB Data Modeling
    1. Table of Contents
    2. MongoDB Data Modeling
    3. Credits
    4. About the Author
    5. Acknowledgments
    6. About the Reviewers
    7. www.PacktPub.com
      1. Support files, eBooks, discount offers, and more
        1. Why subscribe?
        2. Free access for Packt account holders
    8. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    9. 1. Introducing Data Modeling
      1. The relationship between MongoDB and NoSQL
      2. Introducing NoSQL (Not Only SQL)
        1. NoSQL databases types
        2. Dynamic schema, scalability, and redundancy
      3. Database design and data modeling
        1. The ANSI-SPARC architecture
          1. The external level
          2. The conceptual level
          3. The internal level
        2. Data modeling
          1. The conceptual model
          2. The logical model
          3. The physical model
      4. Summary
    10. 2. Data Modeling with MongoDB
      1. Introducing documents and collections
        1. JSON
        2. BSON
      2. Characteristics of documents
        1. The document size
        2. Names and values for a field in a document
        3. The document primary key
        4. Support collections
        5. The optimistic loop
      3. Designing a document
        1. Working with embedded documents
        2. Working with references
        3. Atomicity
      4. Common document patterns
        1. One-to-one
        2. One-to-many
        3. Many-to-many
      5. Summary
    11. 3. Querying Documents
      1. Understanding the read operations
        1. Selecting all documents
        2. Selecting documents using criteria
        3. Comparison operators
        4. Logical operators
        5. Element operators
        6. Evaluation operators
        7. Array operators
        8. Projections
      2. Introducing the write operations
        1. Inserts
        2. Updates
        3. Write concerns
          1. Unacknowledged
          2. Acknowledged
          3. Journaled
          4. Replica acknowledged
        4. Bulk writing documents
      3. Summary
    12. 4. Indexing
      1. Indexing documents
        1. Indexing a single field
        2. Indexing more than one field
        3. Indexing multikey fields
        4. Indexing for text search
      2. Creating special indexes
        1. Time to live indexes
        2. Unique indexes
        3. Sparse indexes
      3. Summary
    13. 5. Optimizing Queries
      1. Understanding the query plan
        1. Evaluating queries
        2. Covering a query
        3. The query optimizer
        4. Reading from many MongoDB instances
      2. Summary
    14. 6. Managing the Data
      1. Operational segregation
        1. Giving priority to read operations
      2. Capped collections
      3. Data self-expiration
      4. Summary
    15. 7. Scaling
      1. Scaling out MongoDB with sharding
        1. Choosing the shard key
        2. Basic concerns when choosing a shard key
      2. Scaling a social inbox schema design
        1. Fan out on read
        2. Fan out on write
        3. Fan out on write with buckets
      3. Summary
    16. 8. Logging and Real-time Analytics with MongoDB
      1. Log data analysis
        1. Error logs
        2. Access logs
      2. What we are looking for
        1. Measuring the traffic on the web server
      3. Designing the schema
        1. Capturing an event request
        2. A one-document solution
        3. TTL indexes
        4. Sharding
        5. Querying for reports
      4. Summary
    17. Index