Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove TTL form MongoDB collection?

I'm using mongoose with node.js. I was testing Time-To-Live features and set my documents to expire after X time in the db schema:

var adInfos = new mongoose.Schema({                           
  inf  : { type: Object, required: false },                    
  created: { type: Date, default: Date.now, expires:60 }
});                                                           

This seems to work right but after removing the expires attribute the new documents still seem to be expiring.

I have also tried setting expires: false and expires:0 but that doesn't work either.

like image 784
user2865156 Avatar asked Oct 22 '25 23:10

user2865156


1 Answers

Mongoose doesn't ever drop indexes, so if you change the index attributes in your schema they won't take effect until after you manually drop the existing index.

Not sure what your collection name is, but in the shell it would be something like:

db.adInfos.dropIndex('created_1')

Use db.adInfos.getIndexes() to see the indexes on the collection.

like image 106
JohnnyHK Avatar answered Oct 24 '25 18:10

JohnnyHK