我正在使用 mongoose 和 node.js。我正在测试生存时间功能,并将我的文档设置为在数据库模式中的 X 时间后过期:
var adInfos = new mongoose.Schema({
inf : { type: Object, required: false },
created: { type: Date, default: Date.now, expires:60 }
});
这似乎工作正常,但删除 expires
属性后,新文档似乎仍然过期。
我还尝试设置 expires: false
和 expires:0
但这也不起作用。
最佳答案
Mongoose 永远不会删除索引,因此,如果您更改架构中的索引属性,它们只有在您手动删除现有索引后才会生效。
不确定您的集合名称是什么,但在 shell 中它会类似于:
db.adInfos.dropIndex('created_1')
使用db.adInfos.getIndexes()
查看集合上的索引。
关于node.js - 如何删除MongoDB集合中的TTL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28356610/