Home > OS >  Mongoose, Aggregation vs Js functions
Mongoose, Aggregation vs Js functions

Time:02-18

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 ...?

CodePudding user response:

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.

  • Related