如何删除 TTL 表单 MongoDB 集合?

How to remove TTL form MongoDB collection?

我在 node.js 中使用猫鼬。我正在测试生存时间功能并将我的文档设置为在数据库模式中的 X 时间后过期:

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

这似乎工作正常,但在删除 expires 属性后,新文档似乎仍将过期。

我也试过设置 expires: falseexpires:0 但这也不起作用。

Mongoose 永远不会删除索引,因此如果您更改架构中的索引属性,它们将在您手动删除现有索引后才会生效。

不确定你的 collection 名字是什么,但在 shell 中应该是这样的:

db.adInfos.dropIndex('created_1')

使用 db.adInfos.getIndexes() 查看 collection 上的索引。