Skip to content
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.

Model.remove fails in getting documents unindexed #5

Closed
jeremythille opened this issue May 15, 2016 · 1 comment
Closed

Model.remove fails in getting documents unindexed #5

jeremythille opened this issue May 15, 2016 · 1 comment

Comments

@jeremythille
Copy link

jeremythille commented May 15, 2016

Using Mongoose's method Model.remove() effectively removes the documents from Mongo, but they remain indexed in Elastic's base.

Ad.remove({
  $where: "this.site.length > 0"
}).exec(function(err, docs) {
     if(err) throw err;
     console.log(docs); // undefined!
});

Many documents are removed from Mongo, but they remain in Elastic.

My guess is that Mexp needs the returned documents in order to update them in ES, but the problem is that the remove() method does not return these documents. Its signature is only err.

Workaround
We can make a 2-step delete, with (1) a find() query and (2) delete the returned documents one by one. findOneAndRemove() returns the deleted document, so it can be unindexed.

@jbdemonte
Copy link
Owner

Yes, mexp only handle document's handlers, not model ones

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants