-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Practical MongoDB Aggregations
By :

First, you will look at an example that demonstrates how to query a sorted subset of data. As with all subsequent examples, this first example provides the commands you need to populate the dataset in your own MongoDB database and then apply the aggregation pipeline to produce the results shown.
You need to query a collection of people to find the three youngest individuals who have a job in engineering, sorted by the youngest person first.
Note
This example is the only one in the book that you can also achieve entirely using the MongoDB Query Language and serves as a helpful comparison between the MongoDB Query Language and aggregation pipelines.
To start with, drop any old version of the database (if it exists) and then populate a new persons
collection with six person documents. Each person record will contain the person's ID, first name, last name, date of birth, vocation, and address:
db = db.getSiblingDB...