Open jeremythille opened 6 years ago
I had the same problem some days ago and used this:
await Model.esSynchronize({ /* query to target only inserted documents */ });
That's only one line more and worked like a charm. I added a field to every inserted document, so that I can easily target them with a query statement in esSynchronize
.
Here is the relevant part of the docs
Hope that helps.
@pkaske got any advice for the deleteMany() step? I'm guessing esSynchronize is only good for adding documents, not removing them?
await Model.insertMany([documents])
This works, all the documents get saved to Mongo, but nothing gets indexed in ES. I believe this is a technical limitation, not a bug, but it is seriously annoying. Instead of this one line, one has to build a
for...of
loop, saving and indexing the documents one by one. So, for 100 documents, this requires 100 DB calls instead of one...I haven't tried it, but I suspect the same goes with
Model.deleteMany()
?Is there a workaround, or will this be fixed either by you or a future Mongoose version?