繁体   English   中英

nodejs获取所有用户并仅返回用户名称,ID,图像不是所有数据

[英]nodejs get all users and return users only name, id, image not all data

我想获取所有用户的姓名、头像、身份证,但 find() 返回该用户的所有数据,如密码、地址等,但我只想要姓名、身份证、头像。这是我的代码

User.find()
.then(data => {

if (data==0) {
  res.status(500).send({
      message:"There are no user"
  });
}else{
  res.status(200).send( data );
}
  
})
  .catch(err => {
res.status(500).send({
  message:
    err.message || "Some error occurred while retrieving tutorials."
});
});

我希望你也使用 mongoose。

User.find({}, 'firstName lastName picture', function(error, data) {
if (error) {
    return res.status(500).send({
        msg: 'Error while finding records',
        data: []
    })
} else {
    return res.send(200).send({
            msg: 'recods found',
            data: data
        })
  }

});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM