Execute Bulk Operations
Learn how best to execute bulk operations in Ecto.
The Repo.update_all
and Repo.insert_all
operations are first discussed here They allow us to update and insert large groups of records with a single query. Although they’re less commonly used than their counterparts update
and insert
, they can be very efficient for certain use cases.
The Repo.update_all
operation
When we use Repo.update
, we need to perform one query for each record we want to update. Let’s look at how we might reset the number_of_plays
counter on our Track
records back to 0
:
Get hands-on with 1400+ tech skills courses.