const timeline = async (req, res) => {
const currentUser = await users.findById(req.params.id);
const currentUserPost = await posts.find({ userId: currentUser._id });
const friendsPost = await Promise.all(
currentUser.followings.map((f) => {
return posts.find({ userId: f });
})
);
const finalpost = currentUserPost.concat(...friendsPost);
//How do I sort the finalpost array with its time timestamps?
};
Hi @Anthony_Ezeh welcome to the community!
I assume you’re using Mongoose? Could you post the schema or some example documents? It’s hard to answer your question without all the information at hand.
Best regards
Kevin