1

The aim is to synchronize fields from certain collections on elasticsearch. With every change on mongodb, this should also be implemented on elasticsearch. I've seen the different packages. For example River. Unfortunately it didn't work out for me so I try without it. Is that the right approach with change streams?

How could you solve that more beautifully? The data must be synchronized with every change (insert, update, delete) on Elasticsearch. For several collections but different for each one (only certain fields per collection). Unfortunately, I don't have the experience to solve this in such a way that it doesn't take much effort if a collection or fields are added or removed

    const res = await client.connect();
    const changeStream = res.watch();
  
    changeStream.on('change', (data) => {
     // check the change (is the chance in the right database / collection)
     // parse 
     // push it to elastic server
    });

I hope you can help me, thanks in advance :)

1 Answer 1

1

Yes. it will work but you have to handle following scenarios

  1. when your node js process goes down while mongodb updates are ongoing.

    you can use resume token and keep track of that token so once your process comes up it can resume from there.

  2. inserting single document on each change.

    it will be overwhelimg for elasticsearch and might result in slow inserts, which will eventually result in sync lag between mongo and elastic. so better collect multiple document in change stream and insert with bulk API operation.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.