简体   繁体   中英

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

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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM