question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is it possible to bulk update using array of values

See original GitHub issue

As I understand the doc, the model update function can only be used with a single object of values. This is usefull to bulk update multiple rows with the same values.

My question is: is it possible to update multiple rows with different values by passing an array of values containing the id or a unique key to match rows with new values?

var data = [{ id: 1, field1: "foo" }, { id: 2, field1: "bar" }];

Model.update(data, {fields: ['field1']});

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:48
  • Comments:51 (18 by maintainers)

github_iconTop GitHub Comments

111reactions
mickhansencommented, Sep 14, 2015

Not possible with Sequelize, or with SQL afaik. You’ll have to implement a custom function, shouldn’t be too hard, just loop and call update 😃

42reactions
Natinuxcommented, Dec 15, 2015

@mickhansen Thanks. I implemented this using Promise.all. I hoped I will be able to do this with one call … Thank you

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to make bulk update with arrays in PostgreSQL?
You can unnest them in a subquery: UPDATE services s SET name = x.name, active = x.active, description = x.description FROM (SELECT ...
Read more >
$pull — MongoDB Manual
The $pull operator removes from an existing array all instances of a value or ... After the update operation, the document only has...
Read more >
Bulk update array / mapping in solidity by a call
You can also use "just-in-time" computations to increment/add/apply function to elements when needed. You can make it self-serve so the cost of ...
Read more >
Bulk API | Elasticsearch Guide [8.5] | Elastic
Routingedit. Each bulk item can include the routing value using the routing field. It automatically follows the behavior of the index / delete...
Read more >
Retrieving and Modifying Values from Result Sets (The Java ...
You cannot update a default ResultSet object, and you can only move its cursor forward. However, you can create ResultSet objects that can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found