Cover Page....2
Table of Contents....3
Preface....4
Chapter 1: MongoDB Aggregations Explained....12
What is the MongoDB aggregation framework?....12
What is the MongoDB aggregation language?....14
What do developers use the aggregation framework for?....16
A short history of MongoDB aggregations....18
Getting going....21
Getting further help....26
Summary....27
Part 1: Guiding Tips and Principles....29
Chapter 2: Optimizing Pipelines for Productivity....30
Embrace composability for increased productivity....30
Better alternatives for a projection stage....36
Summary....43
Chapter 3: Optimizing Pipelines for Performance....44
Using explain plans to identify performance bottlenecks....44
Guidance for optimizing pipeline performance....51
Summary....64
Chapter 4: Harnessing the Power of Expressions....65
Aggregation expressions explained....65
What do expressions produce?....68
Can all stages use expressions?....70
Advanced use of expressions for array processing....73
Summary....96
Chapter 5: Optimizing Pipelines for Sharded Clusters....98
A brief summary of MongoDB sharded clusters....98
Sharding implications for pipelines....100
Where does a sharded aggregation run?....101
Performance tips for sharded aggregations....110
Summary....111
Part 2: Aggregations by Example....113
Chapter 6: Foundational Examples: Filtering, Grouping, and Unwinding....114
Filtered top subset....114
Group and total....119
Unpack arrays and group differently....124
Distinct list of values....129
Summary....133
Chapter 7: Joining Data Examples....134
One-to-one join....134
Multi-field join and one-to-many....139
Summary....145
Chapter 8: Fixing and Generating Data Examples....146
Strongly typed conversion....146
Converting incomplete date strings....151
Generating mock test data....158
Summary....165
Chapter 9: Trend Analysis Examples....167
Faceted classification....167
Largest graph network....176
Incremental analytics....180
Summary....188
Chapter 10: Securing Data Examples....189
Redacted view....189
Mask sensitive fields....197
Role programmatic restricted view....204
Summary....213
Chapter 11: Time-Series Examples....214
IoT power consumption....214
State change boundaries....224
Summary....232
Chapter 12: Array Manipulation Examples....233
Summarizing arrays for first, last, minimum, maximum, and average values....233
Pivoting array items by a key....238
Array sorting and percentiles....243
Array element grouping....252
Array fields joining....259
Comparison of two arrays....263
Jagged array condensing....272
Summary....279
Chapter 13: Full-Text Search Examples....280
What is Atlas Search?....280
Compound text search criteria....281
Facets and counts text search....287
Summary....294
Afterword....295
Index....296
Why subscribe?....301
Other books you may enjoy....303
Packt is searching for authors like you....304
Download a free PDF copy of this book....304
Appendix....306
Officially endorsed by MongoDB, Inc., Practical MongoDB Aggregations helps you unlock the full potential of the MongoDB aggregation framework, including the latest features of MongoDB 7.0. This book provides practical, easy-to-digest principles and approaches for increasing your effectiveness in developing aggregation pipelines, supported by examples for building pipelines to solve complex data manipulation and analytical tasks.
This book is customized for developers, architects, data analysts, data engineers, and data scientists with some familiarity with the aggregation framework. It begins by explaining the framework's architecture and then shows you how to build pipelines optimized for productivity and scale.
Given the critical role arrays play in MongoDB's document model, the book delves into best practices for optimally manipulating arrays. The latter part of the book equips you with examples to solve common data processing challenges so you can apply the lessons you've learned to practical situations. By the end of this MongoDB book, you’ll have learned how to utilize the MongoDB aggregation framework to streamline your data analysis and manipulation processes effectively.
This book is for intermediate-level developers, architects, analysts, engineers, and data scientists who are interested in learning about aggregation capabilities in MongoDB. Working knowledge of MongoDB is needed to get the most out of this book.