Saturday, 15 May 2010

node.js - How Do I Know A Document With Expires Attribute Got Deleted? -



node.js - How Do I Know A Document With Expires Attribute Got Deleted? -

i'm implementing verification procedures in node.js. had each verification stored in mongodb mongoose, , set expires attribute it, deleted after time. this

var verification = new schema({ // else createdat: { type: date, expires: '1d', default: date.now, }, });

but want know when doc deleted. can else, deleting docs related verification. i've tried using post() hooks,

verification.post('remove', function(){ // else };

but seems won't work, since it's on application level. doc deleted mongodb directly, remove() won't called.

you can't know when document deleted because mongodb removes expired documents in background task. there no way check documents deleted.

if need functionality, can create background job delete documents own collections every 60 seconds , notify documents deleted.

node.js mongodb mongoose

No comments:

Post a Comment