Arvind Mohan
Arvind Mohan

Reputation: 59

Partitioning records in a collection in MongoDB

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

Upvotes: 3

Views: 3650

Answers (1)

helmy
helmy

Reputation: 9507

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.

Upvotes: 5

Related Questions