mongoose-elasticsearch-xp
mongoose-elasticsearch-xp copied to clipboard
Why new records not indexed to ES automatically?
OS: MacOS 10.15 Catalina Elasticsearch: 6.8.4 MongoDB: 4.0.3 Mongoose: 5.5.0
A'm already have collection with N records and according documentation I indexed it:
Car.esSynchronize().then(function () { console.log('end.') });
All fine, N records was added to ES index.
Car.esSearch() gives me results:
{ took: 9, timed_out: false, _shards: { total: 5, successful: 5, skipped: 0, failed: 0 }, hits: { total: 2019, max_score: 0, hits: ...
Next I insert/update records in mongodb collection Car:
Car.findOneAndUpdate({ carId }, { $set: data }, { upsert: true, setDefaultsOnInsert: true, useFindAndModify: false });
But nothing inserted/updated automatically in ES!
What I'm doing wrong ?
Hi @cyberz,
As mentionned in the README, you have to use the option { new: true }
in order for findOneAndUpdate
function to work correctly with ES.