mongodb:到期不起作用

编程入门 行业动态 更新时间:2024-10-25 08:26:06
本文介绍了mongodb:到期不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在猫鼬5.0.6中,我希望此架构在创建后1分钟内使文档过期:

In mongoose 5.0.6, I'm hoping this schema to expire documents 1min after creation:

const InvitationTokenSchema = new Schema( { token: { type: String, required: true }, createdAt: { type: Date, default: Date.now, expires: '1m' }, userId: { type: Schema.Types.ObjectId, ref: 'User' }, }, { usePushEach: true, }, );

但是它根本不起作用-所有文档仅在mongo中保留,不会被删除.

However it simply doesn't work - all documents just persists in mongo, not being removed.

在mongo shell中,getIndexes()显示以下内容:

In mongo shell, getIndexes() shows the following:

[ { "v" : 2, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "mydb.invitationtokens" }, { "v" : 2, "key" : { "createdAt" : 1 }, "name" : "createdAt_1", "ns" : "mydb.invitationtokens", "expireAfterSeconds" : 60, "background" : true } ]

可能是什么原因?

推荐答案

正如我看到的代码所示,它是正确的. 另外,该值应为 String ,并且您也可以使用'1m'. 您需要将猫鼬更新到最新版本.

As I see you code, its right. Also, the value should be String and you can use '1m' as well. You need to update the mongoose to the latest version.

使用:npm update mongoose

有关更多详细信息,请在此处搜索过期": mongoosejs/docs/api .html

For more details search for "expires" here: mongoosejs/docs/api.html

更多推荐

mongodb:到期不起作用

本文发布于:2023-11-22 13:03:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1617520.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不起作用   mongodb

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!