class Synapse::EventStore::Mongo::DocumentPerCommitStrategy

Storage strategy that stores all events in a commit operation in a single document

Since Mongo doesn't support transactions, this can be used as a substitute to guarantee atomic storage of events. The only downside is that it may be harder to query events from the event store.

Performance also seems to be better using this strategy

Public Instance Methods

create_documents(type_identifier, events) click to toggle source

@param [String] type_identifier Type identifier for the aggregate @param [Array] events Domain events to be committed @return [Array]

# File lib/synapse/event_store/mongo/per_commit_strategy.rb, line 15
def create_documents(type_identifier, events)
  document = CommitDocument.new
  document.from_events(type_identifier, events, @serializer).to_hash
end
extract_events(hash, aggregate_id) click to toggle source

@param [Hash] hash @param [Object] aggregate_id @return [Array]

# File lib/synapse/event_store/mongo/per_commit_strategy.rb, line 23
def extract_events(hash, aggregate_id)
  document = CommitDocument.new
  document.from_hash(hash).to_events(aggregate_id, @serializer, @upcaster_chain)
end