I have a existing index which is a non-TTL index.
First question is Can I create a index with same field (means Can I create index with ‘date’ field?)
If the answer is yes please do explain how?
If answer is no then how can we convert this non-TTL index into TTL index (add timeToExpire in options)
{
"key": {
"date": 1
},
"options": {
"name": "date_info",
"background": true,
"sparse": true
}
}
Hi @Vartika_Malguri have you tried running something like the following (taken from the TTL Index documentation):
db.runCommand({
"collMod": <collName>,
"index": {
"keyPattern": <keyPattern>,
"expireAfterSeconds": <number>
}
})
This will go through and update an existing index with the expireAfterSeconds
field. I just tested this out on a normal index and the document was deleted after the expireAfterSeconds
period passed.
Yes… I have tried this …This didn’t worked for me
It says no expireAfterSeconds to update
Can you state what version of MongoDB you’re using? I just tested this out on version 6.0.0 and it worked.
Quick note, I just tested with versions 5.0.10 and 4.4.15 and was able to do the same as I did on 6.0.0 and the process worked on those versions as well.