From the course: MongoDB Java Developer Associate Cert Prep

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Returning specific data from a query in MongoDB

Returning specific data from a query in MongoDB

From the course: MongoDB Java Developer Associate Cert Prep

Returning specific data from a query in MongoDB

- Hello, in this video we'll examine two of the most commonly used aggregation pipeline stages, $match and $group. We'll use $match to filter for documents that satisfy a query and use $group to group documents by a group key. The $match stage filters for documents that meet specified conditions and passes those documents to the next stage of the pipeline. The match stage takes one argument, which is a query. This query works exactly like a find command. When using a $match stage, place it as early as possible in the pipeline so that it can use indexes. Because it filters, it reduces the number of documents which lessens the amount of processing required. Let's go through an example of a $match stage. We have a collection that contains all the ZIP codes in the United States. Let's use a $match stage to find all of the ZIP codes from California, which is abbreviated as CA. Great, now, what if we wanted to group all of…

Contents