0

How to do bulk update by Id, in Strapi using mysql database? I'm trying this

await strapi.query('logs').update({id_in : [12,13]}, {is_transfered : 1});

But getting this error

Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ' 13 limit 1' at line 1

What is wrong?

Aidyn
  • 5
  • 1
  • 3

2 Answers2

2

Maybe it's too late for you but for the people who need it in the future: You can get mongodb connection and bulk update it yourself.

      const mongodbInstance = strapi.connections.default;

      await mongodbInstance.models.Logs.update({id_in : [12,13]}, {is_transfered : 1}, {multi: true});

I've written an article about bulk insert and update here you may find useful: https://kursat.github.io/#/post/2021-01-24-strapi-bulk-insert-and-update.md

kursat
  • 1,059
  • 5
  • 15
  • 32
0

This feature doesn't exist in update function that is offered by Strapi.

But if you use strapi.query('logs').model you will have access to the Bookshelf instance.

And if bookshelf supports this feature, then you will be able to bulk update.

Jim LAURIE
  • 3,859
  • 1
  • 11
  • 14