Is multiple delete available in sequelize?

node.jssequelize.js

node.js Problem Overview


I have a multiple contentIds.

Mode.findAll({
    where: {
     id: contentIds
   }
  })

After finding all how can I Delete multiple rows from a table.

Or tell me other options to delete multiple records with a single query.

node.js Solutions


Solution 1 - node.js

Example:

Model.destroy({ where: { id: [1,2,3,4] }})

For more details check the API docs.

Solution 2 - node.js

If you want to delete ALL models of a specific type, you can use:

Model.destroy({where: {}}).then(function () {});

This will delete all records of type 'Model' from database. Tested with mysql;

Solution 3 - node.js

You can use destroy method on a model:

Model.destroy({
  where: {
    id: contentIds
  }
});

For more details check the API docs.

Solution 4 - node.js

To destroy all entries in a model:

Model.destroy({
    where: {}
}).then(function(){
    console.log('destroy all data');
    res.redirect('/');
})

Solution 5 - node.js

Note that if you have paranoid enabled, and you really want to destroy the rows from the table instead of just setting their deleted_at timestamp, pass the option force: true to the Model.destroy({}) method.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAnujView Question on Stackoverflow
Solution 1 - node.jsSergey KarasevView Answer on Stackoverflow
Solution 2 - node.jsMardariView Answer on Stackoverflow
Solution 3 - node.jsNikolay LukyanchukView Answer on Stackoverflow
Solution 4 - node.jsJuan NavarreteView Answer on Stackoverflow
Solution 5 - node.jsAkash AgarwalView Answer on Stackoverflow