簡體   English   中英

Nodejs使用mongoose查找用戶並刪除圖像

[英]Nodejs find user and delete image with mongoose

我要做的是通過 email 找到用戶並從數組中刪除一個項目。

這樣做的正確方法是什么?

所以這是我的代碼:

 Accomodation.findOneAndDelete(
   { email: req.session.passport.user },
   { images: req.body.imageSelected },
   function (error, result) {
     if (error) {
     } else {
       console.log(result);
     }
   }
 );
});``` 

這就是我修復它的方法:

app.post("/accomodation-imgdelete", (req, res, next) => {
  Accomodation.findOneAndUpdate(
    { email: req.session.passport.user },
    { $pull: {images: 2},
    function (error, result) {
      if (error) {
        console.log(error)
      } else {
        console.log(result);
      }
    }
    })
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM