title: golang mgo TTL index
body: <p>how do I create a TTL (time to live) index with golang and mongodb?
  This is how I'm trying to do it currently:</p>
  
  <pre><code>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)
  }
  </code></pre>
  
  <p>But if I look it up using:</p>
  
  <pre><code>db.session.getIndexes()
  </code></pre>
  
  <p>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.</p>