我的網(wǎng)站上有一個(gè)“已關(guān)注”部分,它會檢索用戶已關(guān)注的所有用戶的帖子。有沒有辦法讓這些按日期排序?這是到目前為止的代碼:exports.followedPosts = async (req, res) => { try { const user = await User.findById(req.user._id); const posts = []; for (const follow of user.follows) { const partPosts = await Post.find({ author: follow.user }) .select('-comments') .populate('author') .exec(); for (const post of partPosts) { posts.push(post); } } res.send(posts); } catch (err) { console.error(err.message); res.status(500).send('server error'); }};
貓鼬按日期排序,多個(gè)查詢
繁華開滿天機(jī)
2023-04-01 15:57:46