M
M
MeinJun2020-05-27 20:47:13
MongoDB
MeinJun, 2020-05-27 20:47:13

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')
});


The route of the second button that removes one item from the 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

1 answer(s)
P
Pavel Didenko, 2020-05-28
@MeinJun

Are you using mongoose? deleteMany - deletes everything, deleteOne - one record

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question