-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to remove documents during incoming/outgoing handlers? #45
Comments
try this example from the README to delete a doc when reading out from the db if it’s expired and throwing the missing error var errors = require('pouchdb-errors')
var pouch = new PouchDB('mydb');
pouch.transform({
outgoing: function (doc) {
if (doc.expiresAt < now) {
pouch.remove(doc).then(() => throw errors.MISSING_DOC)
}
return return doc
}
}); hope that helps to point you in the right direction? |
Huh? I definitely do not see this example in the README. That said, your example generally makes sense to me. So throwing a |
I don’t know, you’ll have to experiment with it. Would be great if you could share what you came up with |
So I've tried a number of different variations on the idea from @gr2m's comment above but they all suffer from the same problem: the document isn't fully removed until after the query/read resolves, and this ExperimentsExperiment 1: Remove doc and
|
I'm looking to setup a PouchDB environment such that documents can contain an expiry property (e.g. an
expiresAt
timestamp).As such, I am interested in if I can utilize this plugin's incoming/outgoing functionality to check a document's expiry when being read/written and verify it should still exist. If so, return it; if not, remove it from the database and do not return it.
Looking through the code and issue tracker, it is not at all clear how to achieve this.
The README does, however, mention this basic concept in passing:
Can someone please help me understand how to hook such a thing up?
The text was updated successfully, but these errors were encountered: