In a data collecting/processing application I'm developing, I get a big packet of data, process it, then store the original and the processed in MongoDB using Mongoose. I want to keep a sampling of the original packets (2% of them) but recycle the space used by the other 98% of them. TTL seems like a good way to get this thinning process done.
But the TTL index is a field in the Schema, and can't be applied to some documents and not others.
My current solution to this is to create the schema with TTL:
expiryTimestamp : { type: Date, expires: 3600 }
Then in the documents I want to expire, set expiryTimestamp to a date, and in the ones I keep set it to null
{'expiryTimestamp' : ( keepMe ? null : new Date() )}
1. Is this the intended way to be able to do this or is there a better way to thin the database by expiring certain documents?
2. Will this be supported in future releases of Mongoose?
I am using mongoose 3.8.21 to access mongo 2.6.4