本文主要是介绍Mongodb 设置过期时间Expire Date,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
给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 设置过期时间Expire Date的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!