How to exclude one particular field from a collection in Mongoose?

前端 未结 6 2163
逝去的感伤
逝去的感伤 2020-12-13 12:15

I have a NodeJS application with Mongoose ODM(Mongoose 3.3.1). I want to retrieve all fields except 1 from my collection.For Example: I have a collection Pr

6条回答
  •  忘掉有多难
    2020-12-13 12:43

    I am use this with async await

    async (req, res) => {
          try { 
            await User.findById(req.user,'name email',(err, user) => {
              if(err || !user){
                return res.status(404)
              } else {
                return res.status(200).json({
                  user,
                });
              }
            });
          } catch (error) {
            console.log(error);
          }
    

提交回复
热议问题