how do I create a TTL (time to live) index with golang and mongodb? This is how I'm trying to do it currently:
sessionTTL := mgo.Index{
Key: []string{"created"},
Unique: false,
DropDups: false,
Background: true,
ExpireAfter: session_expire} // session_expire is a time.Duration
if err := db.C("session").EnsureIndex(sessionTTL); err != nil {
panic(err)
}
But if I look it up using:
db.session.getIndexes()
session_expire is set to 5*time.Second. The field "created" in the document is set to current date using time.Now(), so I expected the documents the be deleted after 5 seconds.