我的 main.app 中有此代碼:
app.get('/admin_panel', isAdm, async (req, res)=>{
var records = await add_joke.find({});
res.render('admin_panel', { recs: records });
})
在此之后,我有一個名為 admin_panel 的 ejs 檔案,其中包含以下代碼:
<% for(var i in recs){ %>
<div >
<p ><%= recs[i].title %></p>
<p ><%= recs[i].description %></p>
<a href="/profiles?username=<%= recs[i].post_user %>" >By
<%=recs[i].post_user %></a>
<form action="/admin_panel" method="post">
<input type="hidden" name="id_post" value="<%= recs[i].id %>">
<input type="submit" value="Delete">
</form>
</div>
<% } %>
要洗掉的提交是:
app.post('/admin_panel', async (req, res)=>{
var the_records = req.body;
console.log(the_records);
var the_alg_find = await add_joke.deleteOne({id: the_records.id_post});
console.log(the_alg_find);
res.redirect('/admin_panel');
})
問題是那個帖子表單給了我資料庫中第一個帖子的其余 id 到所有帖子,還有另一種方法可以從像這個例子一樣的迭代中選擇一個特定的專案嗎?謝謝!
uj5u.com熱心網友回復:
為了更好地理解這一點,您可能應該分享您的收藏模式
uj5u.com熱心網友回復:
在您發布的螢屏截圖中,資料庫中的檔案沒有id欄位。因此,您不能參考recs[i].id,并且查詢{ id: somevalue }將不起作用。您的意思是使用該_id欄位嗎?
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/360071.html
上一篇:MongoDb日期查詢問題
