[SOLVED] Mongoose, Aggregation vs Js functions


I need to search my Mongo database and get the average user for each month of the year. Is it more performant to do this directly with a database search using aggregation or would it be better for me to fetch all the data first and organize them with basic javascript functions like for, reduce, map …?


The short answer: MongoDB, because is written in c++ so will be more efficient than your JS function.

The long answer: You can read multiple articles or StackOverflow questions like:

In esence, a DB process is more optimized than a function in JS and is a better option use aggregation framework to do a math operation than JS code.

Answered By – J.F.

Answer Checked By – Pedro (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *