I can create an index with expiredAfterSecconds
this way in the mongo shell:
db.x.createIndex( { "createdAt": 1 }, { expireAfterSeconds: 3600 } )
I can re-do the same command and that's ok for mongo:
> db.x.createIndex( { "createdAt": 1 }, { expireAfterSeconds: 3600 } )
{
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 2,
"numIndexesAfter" : 2,
"note" : "all indexes already exist",
"ok" : 1
}
However, if I try to change the expiredAfterSecconds
value re-creating the index I get and error:
> db.x.createIndex( { "createdAt": 1 }, { expireAfterSeconds: 7200 } )
{
"ok" : 0,
"errmsg" : "Index with name: createdAt_1 already exists with different options",
"code" : 85,
"codeName" : "IndexOptionsConflict"
}
The same if I use ensureIndex()
instead of createIndex()
.
To my knowledge the only way of modifying expireAfterSeconds
value I have found is to drop the index, then create it again, but I wonder if there is another way (maybe some kind of "override" option to be passed to createIndex()
?).
I'm using PyMongo, so if it can solve mongo shell limitations that would be also fine to me.