如何从MongoDB集合中删除TTL表格? [英] How to remove TTL form MongoDB collection?

查看:98
本文介绍了如何从MongoDB集合中删除TTL表格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 }
});                                                           

这似乎正常,但是在删除了expires属性之后,新文档似乎仍将过期.

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

我也尝试设置expires: falseexpires:0,但这也不起作用.

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

推荐答案

猫鼬从不删除索引,因此,如果您更改架构中的索引属性,它们将在您手动删除现有索引之前生效.

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')

使用db.adInfos.getIndexes()查看集合上的索引.

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

这篇关于如何从MongoDB集合中删除TTL表格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆