Answer the question
In order to leave comments, you need to log in
How on node.js + mongo db to delete a record from a table/clear the whole table?
There is a shopping list database. There are 2 buttons: 1 - Must clear the entire list; 2 - Built into each list item and should remove it from the database when clicked. How to implement it? Found mongoose.connection.db.dropDatabase but couldn't get it to work.
Route 1 of the button that clears the entire table:
router.post('/clear_list', async (req, res)=>{
const list = await SchemaList.<УДАЛИТЬ ДАННЫЕ ВСЕЙ СХЕМЫ>
await list.save();
res.redirect('/list')
});
router.post('/del_elem', async (req, res)=>{
const list = await SchemaList.<УДАЛИТЬ ЭТОТ ЭЛЕМЕНТ>
await list.save();
res.redirect('/list')
});
Answer the question
In order to leave comments, you need to log in
Are you using mongoose? deleteMany - deletes everything, deleteOne - one record
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question