diff options
Diffstat (limited to 'db/mongo.go')
| -rw-r--r-- | db/mongo.go | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/db/mongo.go b/db/mongo.go index 83e71f7..4c8a739 100644 --- a/db/mongo.go +++ b/db/mongo.go @@ -35,6 +35,21 @@ func initSessions(user, pass, ip string) { log.Fatalf("error establishing connection to mongo: %s", err.Error()) } + // ensure expiry check + sessionTTL := mgo.Index{ + Key: []string{"expiry"}, + ExpireAfter: 0, + } + + // ensure hashes are unique + uniqueHashes := mgo.Index{ + Key: []string{"hash"}, + Unique: true, + } + + _ = Session.DB("main").C("pastes").EnsureIndex(sessionTTL) + _ = Session.DB("main").C("pastes").EnsureIndex(uniqueHashes) + // Define connection to Databases pastes = Session.DB("main").C("pastes") } |