如何在mongoose中取消选择特定文档

7cjasjjr  于 2022-11-13  发布在  Go
关注(0)|答案(1)|浏览(140)

我可以访问userId,我想得到的结果没有文档的特定用户。我怎么能做到这一点在mongoose?

async peopleyoumayknow(req, res) {
    const {id} = req.params
    const response = await userModel.find({}).sort({creation_date:-1}).limit(12)
    return res.send(response)
}
iugsix8n

iugsix8n1#

将代码更新为

async peopleyoumayknow(req, res){
    const {id} = req.params
    const response = await userModel.find({ _id: {"$ne": id}}).sort({creation_date:-1}).limit(12);
    return res.send(response)
  }

相关问题