mongodb 集合设置过期时间

转载 http://blog.csdn.net/superdangbo/article/details/50964392

给collection:AuthCode 设置过期时间Expire Date 为5分钟 :


 db.AuthCode.ensureIndex({"createdAt": 1},{expireAfterSeconds: 300})


步骤:

[root@app bin]# ./mongo 127.0.0.1:27017

MongoDB shell version: 3.0.6
connecting to: 127.0.0.1:27017/test
> use appdb
switched to db appdb
> db.auth("appUser","12345678")
1
> show collections
system.indexes
test
> db.createCollection('AuthCode')
{ "ok" : 1 }
> show collections
AuthCode
system.indexes
test
> db.AuthCode.ensureIndex({"createdAt": 1},{expireAfterSeconds: 300})
{
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 1,
"numIndexesAfter" : 2,
"ok" : 1
}
> db.AuthCode.find()
{ "_id" : ObjectId("56f2538c65a85d5d2ce01d26"), "mobile" : "12345678901", "code" : "471892", "createdAt" : ISODate("2016-03-23T08:27:56.572Z") }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值