Tips for working with the MongoDB aggregation framework
- Review the data.
What are the data types? What is the structure? What do the values mean?
- Build out the query one stage at a time.
- Start with one pipeline operation and a limit operation at the end. Review that you are getting the results you expect. Keep the limit operation in place as you add operations. Verify expected behavior every step of the way.
- Remove the limit operation as the last step .
The online documentation will be very useful:
This reference includes some nice material regarding comparison with standard SQL operations: http://docs.mongodb.org/manual/reference/sql-aggregation-comparison/