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

One-to-one join

Sometimes, you need to join data between two collections, where one document in the first collection maps to one, and only one, document in the second collection. This section provides an example of performing this one-to-one join using the $lookup aggregation stage in MongoDB.

Note

For this example, you require MongoDB version 4.4 or above. This is because you will use the $first array operator introduced in version 4.4.

Scenario

You want to generate a report to list all shop purchases for 2020, showing the product's name and category for each order, rather than the product's ID. To achieve this, you need to take the customer orders collection and join each order record to the corresponding product record in the products collection. There is a many-to-one relationship between both collections, resulting in a one-to-one join when matching an order to a product. The join will use a single field comparison between both sides, based on the product...

lock icon The rest of the chapter is locked
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}