feathers.js - saving one record to multiple databases - mysql and elastic search

477 Views Asked by At

I have built an app with Feathers.js and I'm trying to find the way, how can I save any record to the multiple databases? I would like to save a "message" for example to the mysql and also to the elastic search.

I would like to use elastic search for "full text" search, but I would also like to have all data saved in some relational database.

I've created a service using:

feathers generate service

but I can select only one specific database there.

Any help will be really appreciated.

1

There are 1 best solutions below

0
On

Fast way to me is to create another feathers app (microservice) for elasticsearch and post the data to elasticsearch too. If you are using socket in the frontend app you can define 2 sockets (1 for each micro service). When you post new data to feathers app 1 (mysql) you can :

  • on response of the data created post the same data to feathers app 2 (elasticsearch)
  • on error abort and correct

or

  • add a service('your_post_service').on('created', ... and then post data to feathers app 2 (elasticearch)