MongoDB - How to delete expired documents except last one

瀏覽次數:53 次
跳到第一則未讀訊息

Josip Grgurica

未讀,
2016年4月11日 清晨7:45:442016/4/11
收件者:mongodb-user
Hi,

We're working on audit log solution for one of our projects and would appreciate your help. We have media entity which contains media id (numeric), action (string, eg. PUBLISH) and occurred on date with time representing date and time when action happened. Requirement is to delete logs that are older than 90 days but to keep log with last action on media entity.

We are using Mongo 3.2 and we need help how to organize our collection since we need to support reads and writes on collection that will contain 200-300 millions of documents.

We tried several approaches but couldn't figure out a simple way on how to do it. Any suggestions on how to organize schema for this scenario?

Thanks,
Josip

Weishan Ang

未讀,
2016年4月12日 清晨5:35:182016/4/12
收件者:mongodb-user
Hi,

How about using TTL documents?

Kevin Adistambha

未讀,
2016年4月14日 凌晨1:30:112016/4/14
收件者:mongodb-user

Hi Josip,

Could you elaborate further on your requirements? For example:

  • A step by step walkthrough of your process, and the use case associated with it
  • Example documents (“media entity”, “action”, “log”, “lastaction”, etc.)
  • What approaches have you tried so far

Best regards,
Kevin

Josip Grgurica

未讀,
2016年4月14日 上午8:39:212016/4/14
收件者:mongodb-user
Hi,

@Weishan Ang: Thanks you on the suggestion but TTL documents don't solve requirement to keep  log with last action on media entity.

@Kevin Adistambha: We have decided to use separate collection for this problem but thank you on help.
回覆所有人
回覆作者
轉寄
0 則新訊息