From the course: MongoDB Aggregation Pipeline: Advanced Data Analysis and Manipulation

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Aggregation vs. standard queries

Aggregation vs. standard queries

- [Narrator] If you look at the $match operator, you wouldn't be wrong to assume that it does the same thing as the find method on a collection. So what is the difference between running an aggregation function versus a standard query using one of the many collection methods like find or findOne that MongoDB provides? And if they do the same thing, should we just use aggregations for everything to keep our code base and queries as uniform as possible? The answer to the second question is a resounding no. Aggregations should only be used when necessary as there is additional overhead to put documents through the aggregation pipeline. When you call the find method on a collection the database only has to deal with BSON or Binary JSON. This is how MongoDB stores documents in the database so there is less processing that needs to happen to find the documents you are requesting and then those documents are again sent as…

Contents