Reputation: 6020
I am busy considering using a TTL index on a collection in MongoDB and wondering what the effect would be in the event of a restore.
For example, if I set the TTL on a collection to 2 days:
db.logEvents.ensureIndex({"datestamp":1},{expireAfterSeconds:172800})
If I were to back up the daily using mongodump restore a week later, would the logEvents collection be empty? For mongodump / mongorestore, I was considering modifying / removing the index manually in logEvents.metadata.json
before restoring - would this work?
What about if restoring from raw data files - how can I start up the mongod service with restored raw files in the datadir without immediately expiring data?
Upvotes: 5
Views: 1052
Reputation: 9473
This is a nice problem!
To check that I created a collection and tested your scenario, where restored data is outside of the ttl.
The records were restored and in next few seconds removed from collection.
After changing index details in metadatafile I was able to list records outside original ttl window.
removed entry:
,"expireAfterSeconds":36.0
Restoring from raw files could also have a play as long as you are using NMAP
engine.
WiredTiger
stores some extra data outside files and I was unable to restore collection from WT file.
Have a fun!
Upvotes: 6