Sequelize update does not work anymore: "Missing where attribute in the options parameter passed to update"

The official API documentation suggests using Model.update like this:

var gid = ...;
var uid = ...;

var values = { gid: gid };
var where = { uid: uid };
myModel.update(values, where)
.then(function() {
    // update callback
});

But this gives me: “Missing where attribute in the options parameter passed to update”.
The docs also mention that this usage is deprecated. Seeing this error makes me think, they already changed it. What am I doing wrong?

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

Apparently, the docs have not been updated yet. But the table’s where row of the Model.update API docs suggests prefixing your selection with where, like so:

var gid = ...;
var uid = ...;

var values = { 
  gid
};
var selector = { 
  where: {
    uid
  }
};
await myModel.update(values, selector);
// done!

And it works!

UPDATE:

The docs have since been updated (and the docs have also been moved). Check out Model.update on docs.sequelize.com. Note that options.where is not optional (it is not in brackets []).

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply