Array Manipulation Examples
Storing and processing documents with fields that contain arrays of sub-documents is an essential aspect of MongoDB. The aggregation framework offers rich operators to process array contents, which is important to avoid performance penalties from needlessly unwinding and regrouping arrays. The aggregation pipeline's ability to handle nested operations makes even the most challenging array manipulation tasks feasible. However, these solutions can sometimes appear complicated. In this chapter, you will learn how to break down array manipulation problems into manageable pieces, streamlining your assembly of solutions.
This chapter will cover the following topics:
- Generating summaries of array contents, such as highs and lows
- Sorting and changing the orientation of the contents of arrays
- Calculating averages and percentiles for arrays
- Grouping elements of arrays by common keys
- Joining elements from different array fields together...