rwynn / monstache

a go daemon that syncs MongoDB to Elasticsearch in realtime. you know, for search.
https://rwynn.github.io/monstache-site/
MIT License
1.29k stars 182 forks source link

Version conflict on collection relation #704

Open a-jaouen opened 11 months ago

a-jaouen commented 11 months ago

Hello,

Thank you very much for your fantastic work! It was a real relief not to have to create that kind of tool by myself :).

I first describe my config (I'll try to be concise), then my issue and finally a solution to mitigate the issue.

Actual config:

monstache version 6.7.16
Go version go1.20.4
MongoDB go driver v1.12.1
Elasticsearch go driver 7.0.31
MongoDB version 6.0.6
Elasticsearch version 8.11.0

I have 2 collections: collA and collB each in its own database belonging to the same MongoDB instance. I am joining those two collections into one ES index consolidatedIndex, the documents of collB having a field named collAId relating to collA._id Relation is one to one between those collections.

I defined the relation in monstache.config.toml

[[relate]]
namespace = "dbB.collB"
with-namespace ="dbA.collA"
src-field = "collAId"
match-field = "_id"
match-field-type = "objectId" # `collAId` is a string
keep-src = false

And I use a transformation Javascript plugin to join both collections using findOne on collB.

It happens very often in my project the following:

  1. Insert a document into collA
  2. a few seconds later approximately at the same time: a. Insert related document to collB b. update the collA document

It happens from time to time (and once it started it will repeat very often), that I get a version conflict and that my data fail to have last document version from collA.

My question: How is version generated by default when collB trigger a change since it relates to collA? How should I address this issue?

Thank you very much for your help!