简体   繁体   English

自从DELETE调用以来X时间之后,如何删除mongodb(mongoose)上的文档?

[英]How to delete a document on mongodb(mongoose) after X time since the DELETE call?

When I http.delete(api, params, etc..), I don't wanna delete the document immediately, just schedule the deletion after x time depending on a param. 当我http.delete(api,params等。)时,我不想立即删除文档,只是根据参数将删除时间安排在x时间之后。

I was thinking to use setTimeout? 我在想使用setTimeout? is that a good way of doing that? 这是个好方法吗? what's the proper way to approach this thanks.. 解决这种感谢的正确方法是什么?

if you wanted to delete a document at fix time after insert /update ,you can use a ttl index ,when use ttl index the data will not be delete immediately ,but if the delete time is not fix (may related to your param ) . 如果要在插入/更新后的固定时间删除文档,则可以使用ttl索引,使用ttl索引时不会立即删除数据,但是如果删除时间不固定(可能与您的参数有关)。 you can't use the ttl index . 您不能使用ttl索引。

for the scond case . 对于第二个案件。 you have to write a applicantion to monitor the collection 您必须写一份申请书来监控收集情况

compare the data_time delay_time now then delete ,the better is with aggregation . now比较data_time delay_time然后删除,最好使用聚合。

what is more the setTimeout() is a good way to callback after a certain period of time . 更重要的是, setTimeout()是在一段时间后回调的好方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM