I'm using the expires
field in a mongoose schema in order to set expiration on a given field. For instance:
var Crumbs = new Schema({
...
timestamp: {
type: Date,
expires: 3600,
required: true
},
...
});
The effect is the expected one and the following index is created at MongoDB if the index doesn't previously exist:
> db.crumbs.getIndexes()
[
...
{
"v" : 2,
"key" : {
"timestamp" : 1
},
"name" : "timestamp_1",
"ns" : "mydb.crumbs",
"expireAfterSeconds" : 36000,
"background" : true
}
]
However, if the index previously exists it is not created. For instance, if I change to expires: 360
in my code and I re-run my program, "expireAfterSeconds"
at MongoDB keeps being 36000
.
Is there any way to force the index to use the value defined in the schema, even if the index already exists?