Conclusion / Learn

Video Transcript (English)

In this unit we learned to modify query results with MongoDB.

First we saw how to return query results in a specified order using cursor.sort().

The sort() method takes a sort document parameter that defines the sort order of the result set

We also saw how to constrain the number of results returned using cursor.limit().

The `limit()` method has one parameter, the maximum number of documents to return.

Remember that limiting the number of results can enhance the performance of your app by avoiding unnecessary data processing.

We then practiced returning selected fields from a query using projection.

We saw how to specify fields to return by adding a projection document as a second parameter in calls to `find()`.

We now know that inclusion & exclusion statements can't be combined in projections.

The `_id` field is an exception to this rule. We can exclude the `_id` field in any projection, including when we are explicitly including other fields.

Finally, we learned to count the number of documents matching a query using db.collection.countDocuments().

The countDocuments() method has one parameter, a query document.

Now that you’ve learned how to modify query results using the MongoDB shell, you might want to learn how to carry out these operations in your programming language of choice, using one of MongoDB’s client drivers.

Review MongoDB’s documentation on CRUD operations with specific language drivers or check out one of MongoDB’s drivers courses for more information.

Congratulations on completing this unit on modifying query results with MongoDB.