Create multiple rows in table from array?

Is possible to add multiple rows at once from array with sequelize.js? This is my code:

  var user = User.build({
    email: req.body.email,
    password: req.body.password,
    userlevel: '3',
  });

  User
  .find({ where: { email: req.body.email } })
  .then(function(existingUser){

    if (existingUser) {
      return res.redirect('/staff');
    }

    user
    .save()
    .complete(function(err){
      if (err) return next(err);
      res.redirect('/staff');
    });
  }).catch(function(err){
    return next(err);
  });

Thanks for any advise!

There has been an update in the document. check this link

https://sequelize.org/v5/manual/instances.html#working-in-bulk–creating–updating-and-destroying-multiple-rows-at-once-

User.bulkCreate([
  { username: 'barfooz', isAdmin: true },
  { username: 'foo', isAdmin: true },
  { username: 'bar', isAdmin: false }
])


The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .
Read More:   How does !!~ (not not tilde/bang bang tilde) alter the result of a 'contains/included' Array method call?

Similar Posts