Reputation: 913
I have a question about expire TTL settings on documents.
My use case:
My application is kind of aggregator service. It creates one new collection per source. Sources may come and go (read die). My data access pattern is less number of reads and more number of writes. While some of core collections (which do not change) are indexed, collections that application creates per source are not indexed. Generally whole data or partial subset of data (like just 10 records) from that collection is fetched so no need to index really.
Problem:
Those dynamic collections from sources are getting bigger and after certain period of time, we don't need older documents from these collections. So I was thinking of applying "expire TTL settings". However, I had few questions around it.
Questions:
Upvotes: 1
Views: 1592
Reputation: 27487
Expire TTL settings on a document are implemented and enforced thru an index on a BSON date object with the expireAfterSeconds flag set. So you have to have an index on that field in order to make TTL work. Not certain why you have an issue about indexing the documents but this is the only way that TTL works.
Regarding does the index created help in searching - yes it does. You can test this by creating an index on a date object using expireAfterSeconds and then run a a query on that field and use explain() - you will see that it does use the index for a search.
Regarding deleting the collection no it does not do that - it just deletes documents that are expired.
Upvotes: 3