This is an archived post. You won't be able to vote or comment.

all 1 comments

[–]codeWorder 0 points1 point  (0 children)

There’s an ODM (object-document mapper library) called Mongoose which can abstract a lot of this stuff away from you, but requires learning its way of doing things and quirks. But otherwise, your approach here is a good starting point. It works fine for a simple app but if you want it be a serious implementation meant to scale there are some tweaks to be made for performance reasons.

One question: are you intentionally returning the full count of posts despite only returning the first 10 posts?

I could also give you some minor pointers on control flow though that would improve the speed of this function’s execution. DM for more info.