Siva talks about the MongoDB Aggregation operators and how to use them to get the maximum benefits. Good code samples help us understand complex use-cases!
Most programmers who use MongoDB may have heard about its aggregation framework but only a few have used it to its full potential. Recently, in one of our projects, we got a complex requirement where the user needed to generate a report of sales done for any day, month or year. Using just MongoDB queries would have been very slow compared to the aggregation framework. So I decided to take up the challenge and learn the aggregation operators and make my code awesome! Here are the operators that helped me:
1. $and
$and
is one of the MongoDB aggregation conditional operators where you can specify multiple conditions. Any document which satisfies all these conditions would get forwarded to next stage in the pipeline which is nothing but $group
stage. Here is an example
The above example returns the $agreement_amount
if it is today’s booking.
Similar to…
View original post 200 more words