Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Practical MongoDB Aggregations

You're reading from  Practical MongoDB Aggregations

Product type Book
Published in Mar 2024
Publisher Packt
ISBN-13 9781835884362
Pages 278 pages
Edition 1st Edition
Languages
Author (1):
Paul Done Paul Done
Profile icon Paul Done

Table of Contents (20) Chapters

Preface Chapter 1: MongoDB Aggregations Explained Part 1: Guiding Tips and Principles
Chapter 2: Optimizing Pipelines for Productivity Chapter 3: Optimizing Pipelines for Performance Chapter 4: Harnessing the Power of Expressions Chapter 5: Optimizing Pipelines for Sharded Clusters Part 2: Aggregations by Example
Chapter 6: Foundational Examples: Filtering, Grouping, and Unwinding Chapter 7: Joining Data Examples Chapter 8: Fixing and Generating Data Examples Chapter 9: Trend Analysis Examples Chapter 10: Securing Data Examples Chapter 11: Time-Series Examples Chapter 12: Array Manipulation Examples Chapter 13: Full-Text Search Examples Afterword
Index Other books you may enjoy Appendix

Trend Analysis Examples

This chapter showcases the capabilities of the MongoDB aggregation framework in performing advanced data analytics. The framework empowers users to analyze rich datasets, discerning trends, classifications, and relationships.

This chapter will cover the following:

  • Classifying data by different facets
  • Traversing the graph of relationships between documents in the same collection
  • Performing incremental analytics to generate reports

Faceted classification

A typical scenario, often seen as a navigation bar on the left-hand side of an e-commerce product search website, is the need to characterize the same data across multiple dimensions or facets. This example will show you how to perform these faceting queries from a single aggregation pipeline.

Scenario

You want to provide faceted search capability on your retail website to enable customers to refine their product search by selecting specific characteristics against the product results listed on the web page. It is beneficial to classify the products by different dimensions, where each dimension, or facet, corresponds to a particular field in a product record (e.g., product rating or product price).

Each facet should be broken down into a separate range so that a customer can select a specific sub-range (e.g., 4-5 stars) for a particular facet (e.g., rating). The aggregation pipeline will analyze the products collection by each facet's field (rating...

Largest graph network

Sometimes your data may include graph relationships between records within a single collection. Take, for instance, a document management system database that houses whitepapers citing other whitepapers within the same collection. Visualizing the chain of dependencies becomes crucial in such situations. This example shows how you can traverse these sorts of relationships within a collection.

Scenario

Your organization wants to know the best targets for a new marketing campaign based on a social network database such as Twitter.

You want to search the collection of social network users, each holding a user's name and the names of others who follow them. You want to traverse each user record's followed_by array to determine which user has the most extensive network reach.

Note

This example uses a simple data model for brevity. However, this is unlikely to be an optimum data model for using $graphLookup at scale for social network users with...

Incremental analytics

As a company matures, its volume of historical business data expands. This growth presents a significant challenge for the business intelligence department tasked with producing daily sales reports that must capture trends spanning years. The rising data volume increasingly delays the reporting process, impeding swift decision-making based on current financial data. The following example shows how you can avoid an increasing slowdown in reporting.

Scenario

You have accumulated shop orders over many years, with the retail channel continuously adding new order records to the orders collection throughout each trading day. You want to frequently generate a summary report so management can understand the state of the business and react to changing business trends. Over the years, it has taken increasingly longer to generate the report of all daily sums and averages because there has been increasingly more data to process each day.

From now on, to address this...

Summary

In this chapter, you learned various methods for performing advanced analytics and reporting efficiently against data in a MongoDB database.

In the next chapter, you will explore examples of using aggregation pipelines to access and distribute data securely.

lock icon The rest of the chapter is locked
You have been reading a chapter from
Practical MongoDB Aggregations
Published in: Mar 2024 Publisher: Packt ISBN-13: 9781835884362
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}