Henrique Ramos
Henrique Ramos

Reputation: 786

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

Upvotes: 1

Views: 1108

Answers (1)

J.F.
J.F.

Reputation: 15197

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.

Upvotes: 4

Related Questions