Monday, 3 June 2019

Some interesting questions about nodejs backend with Algolia as external search engine

Hi,I am doing a personal project using nodejs and Algolia. My challenge there is the best way to deal with synchronization with MongoDB and Algolia DB.Currently, I am splitting up the "cover data" that is in Algolia DB and "content data" that is in MongoDB, and I am using MongoDB's returned ID as the bridge connecting these two.What I am running at is how should I deal with the error handling for posting new data. In my case, I first save it to the MongoDB, then save it into Algolia DB. But if some errors occur when inserting into Algolia DB, I also need to delete the already saved data in MongoDB.My approaches first are deleting the saved data if an error occurs and second using Promise.all(). However, Promise.all() still saves the first data to mongo even though it will give rejection eventually, and the first approach seems a bit inefficient. Is there a better way(efficient or elegant) to handle this?​Thanks in advance,Junchen

Submitted June 03, 2019 at 09:45PM by GreatFireWallSucks

No comments:

Post a Comment