mongodb 集合设置过期时间
2016-09-22 14:31
302 查看
转载 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") }
>
给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") }
>
相关文章推荐
- mongodb 设置过期时间 mongodb缓存
- Mongodb 设置过期时间Expire Date
- Mongodb 设置过期时间Expire Date
- 设置IIS过期时间
- 在tomcat中设置session过期时间
- 本机时间设置错误导致Cookie过期
- IIS使用十大原则,(IIS过期时间,IIS缓存设置) 【转载】
- 动态设置Cookies过期时间
- Asp操作Cookies(设置[赋值]、读取、删除[设置过期时间])
- IIS使用十大原则,(IIS过期时间,IIS缓存设置) 【转载】
- ASP.NET设置Session过期时间
- Session过期时间的四种设置方式
- 设置cookies过期时间的几种方法
- Session过期时间的四种设置方式
- Session过期时间的四种设置方式
- asp设置cookies过期时间
- 在tomcat中设置session过期时间
- SQL复制中,订阅存在服务器上的过期时间设置
- 如何设置ASP.NET页缓存的过期时间值
- 操作cookie,并设置Cookie过期时间