Partitioning records in a collection in MongoDB

泄露秘密 提交于 2019-12-11 11:01:08

问题


I have an usecase where a set of records in a collection need to be deleted after a specified interval of time. For ex: Records older than 10hours be deleted every 10th hour.

We have tried deletion based on id but found it to be slow.

Is there a way to partition the records in a collection and drop a partition as and when required in Mongo


回答1:


MongoDB does not currently support partitions, there is a JIRA ticket to add this as a feature (SERVER-2097).

One solution is to leverage multiple, time-based collections, cycling collections in a similar way as you would partitions. Typically we would do this when you'd usually only be querying one or few of these time-based collections. If you would often need to read across multiple collections, you could add some wrapper code to simplify that.

There's also TTL Indexes, which leverage a background thread in the mongod server to handle the deletes for you.

Your deletes by _id may have been slow for a number of reasons, and probably warrants more investigation beyond your original question.



来源:https://stackoverflow.com/questions/46427095/partitioning-records-in-a-collection-in-mongodb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!