MongoDB/mongoose aggregation framework: pipeline vs pipeline builder performance

Viewed 14

I'm learning the aggregation framework in MongoDB, and was wondering about the difference between the following two snippets of code:

const data1 = await User.aggregate([{ $match: { username: "hackerman123" } }]);
const data2 = await User.aggregate().match({ username: "hackerman123" });

They do the same thing, but the second one is more readable. Does it make a difference (in terms of performance) which one I use? I tried testing how long each one takes, but due to how simple my queries currently are, and the small size of my test database, I'm getting too much variance to come to a conclusion.

0 Answers
Related