Skip to content

Commit

Permalink
Fix mailhog/MailHog#35 - message list sorting with mongodb storage
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-kent committed Feb 24, 2015
1 parent 54c0c5d commit 153c814
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ func CreateMongoDB(uri, db, coll string) *MongoDB {
log.Printf("Error connecting to MongoDB: %s", err)
return nil
}
err = session.DB(db).C(coll).EnsureIndexKey("created")
if err != nil {
log.Printf("Failed creating index: %s", err)
return nil
}
return &MongoDB{
Session: session,
Collection: session.DB(db).C(coll),
Expand Down Expand Up @@ -54,7 +59,7 @@ func (mongo *MongoDB) Search(kind, query string, start, limit int) (*data.Messag
// List returns a list of messages by index
func (mongo *MongoDB) List(start int, limit int) (*data.Messages, error) {
messages := &data.Messages{}
err := mongo.Collection.Find(bson.M{}).Skip(start).Limit(limit).Select(bson.M{
err := mongo.Collection.Find(bson.M{}).Skip(start).Limit(limit).Sort("-created").Select(bson.M{
"id": 1,
"_id": 1,
"from": 1,
Expand Down

0 comments on commit 153c814

Please sign in to comment.