ποΈ π Using the library database
Select the library database
ποΈ π Empty aggregation pipeline
An empty aggregation
ποΈ π $match
The $match operator is used in conjunction with the aggregation framework to filter documents in a collection. It takes a document as input and returns a new document containing only the documents that match the specified criteria. The syntax for the $match operator is as follows:
ποΈ π $project
Including fields in a projection
ποΈ π $limit
If we return too many documents, but we're interested just in a few, we can limit the number of documents returned using $limit
ποΈ π Combining stages
Up until now, we've just been using one stage in the pipeline. But the power of the aggregation pipeline is that we can use many stages, and the output of one will be the input of the next. Think of it as UNIX pipes or using functional programming with map, filter, reduce, flatmap, etc.
ποΈ π Writing long pipelines
Aggregation pipelines can get very long, depending on how many stages we need to run. Writing a pipeline is writing code, as you will write it using one of the many MongoDB drivers in your own language. Here we're presenting the examples using JavaScript suitable for the MongoDB Shell mongosh, but if you are writing a microservice in Rust, you'll definitely write your pipelines in Rust.
ποΈ π¦ΈββοΈ Repeating stages
Extra activity, do it if you have extra time or are following at home, won't be covered during the hands-on Lab
ποΈ π¦ΈββοΈ Aggregation options
Extra activity, do it if you have extra time or are following at home, won't be covered during the hands-on Lab