Skip to content

Commit

Permalink
Fix event sort order on load
Browse files Browse the repository at this point in the history
  • Loading branch information
totemcaf committed Dec 28, 2023
1 parent 872116c commit b92591c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion eventstore/mongodb_v2/eventstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import (
"github.com/looplab/eventhorizon/uuid"
)

const Ascending = 1

// EventStore is an eventhorizon.EventStore for MongoDB, using one collection
// for all events and another to keep track of all aggregates/streams. It also
// keeps track of the global position of events, stored as metadata.
Expand Down Expand Up @@ -588,7 +590,7 @@ func (s *EventStore) LoadSnapshot(ctx context.Context, id uuid.UUID) (*eh.Snapsh

func (s *EventStore) makeFindOptions() *mongoOptions.FindOptions {
if s.sortEventsOnDb {
return options.Find().SetSort(bson.M{"version": -1})
return options.Find().SetSort(bson.M{"version": Ascending})
}
return options.Find()
}
Expand Down

0 comments on commit b92591c

Please sign in to comment.