Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8507269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:49:20+00:00 2026-06-11T02:49:20+00:00

When setting up mongodb persistence for Oliver’s EventStore , is registering of BsonClassMap for

  • 0

When setting up mongodb persistence for Oliver’s EventStore, is registering of BsonClassMap for each event type required? If I don’t do this, I get the exception Unknown discriminator value 'InventoryItemCreated'. I register all event types with MongoDB, like I described here, and then configure my event store:

var types = Assembly.GetAssembly(typeof(SimpleCQRS.Event))
                    .GetTypes()
                    .Where(type => type.IsSubclassOf(typeof(SimpleCQRS.Event)));
foreach (var t in types)
    BsonClassMap.LookupClassMap(t);

var store = Wireup.Init()
            .UsingMongoPersistence("mongo", new DocumentObjectSerializer())
            .UsingSynchronousDispatchScheduler()
            .DispatchTo(new DelegateMessageDispatcher(DispatchCommit))
            .Build();

Is this really necessarily to do?

I ran into this problem while modifying Greg Young’s “simplest thing” to support Oliver’s event store with MongoDB persistence, code is on github.

Some related observations (tldr)

If I don’t register the event types, I can start with an empty event store (because the events don’t need to be deserialized). I can add a single inventory item and my event store has a single commit:

/* 0 */
{
  "CommitId" : new BinData(3, "4iXrzvzNYEyKmGweCKkOVQ=="),
  "CommitStamp" : ISODate("2012-08-01T08:08:35.795Z"),
  "Dispatched" : true,
  "Events" : [{
      "StreamRevision" : 1,
      "Payload" : {
        "Headers" : { },
        "Body" : {
          "_t" : "InventoryItemCreated",
          "Version" : 0,
          "_id" : new BinData(3, "36qvklv+xU2+mDhVUlzmBg=="),
          "Name" : "abc"
        }
      }
    }],
  "Headers" : { },
  "_id" : {
    "StreamId" : new BinData(3, "36qvklv+xU2+mDhVUlzmBg=="),
    "CommitSequence" : 1
  }
}

When I restart the application and replay this single event, it can’t deserialize PayLoad.Body, because of Unknown discriminator value 'InventoryItemCreated'.

I found two alternative ways to successfully replay the InventoryItemCreated event:

  • When I create another inventory item before replaying, I can replay
    all events; apparently MongoDB then knows of the discriminator.
  • Manually change the discriminator to the full type name:
/* 0 */
{
  // ..
  "Events" : [{
      "StreamRevision" : 1,
      "Payload" : {
        "Headers" : { },
        "Body" : {
          "_t" : "SimpleCQRS.InventoryItemCreated, SimpleCQRS",
        // ..

It strikes me as a bit awkward that apparently the systems can work without registering all event types, but picks a default discriminator determining strategy that prevents this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T02:49:22+00:00Added an answer on June 11, 2026 at 2:49 am

    I’ve encountered the same situation. For right now, I perform the BSON registration in a similar manner that you’ve described. It doesn’t bother me to have the system perform this registration on startup.

    Also, I keep my events and commands classes in a separate project from the actual domain logic as I can then ‘share’ the class structures in both the server and client projects.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I installed MongoDB via Brew and now I get this error: /Library/StartupItems/MongoDB has not
Setting onchange event for CheckBoxList using the following code doesn't work. chkListUserGroup.Attributes.Add(onchange, document.forms[0].isRecordModified.value='true';); How
Setting up environment variables for hundreds of tests get old very quick. Is there
I want to use default SLF4J + Logback configuration except setting org.springframework.data.document.mongodb logging level
I'm in the process of setting up mongodb, and we use puppet to control
I am setting up a mongoDB db to allow (simple) keyword searching using multikeys
How does setting the WriteConcern flag to SAFE in the java driver affects MongoDB
Right now, I have configuration setting for morphia talks to one MongoDB from Play!.
Any recommended readings for setting up mongodb for sharding/scalability? I'm looking for best practices.
I've been using the connection option :connecttimeoutms when setting up MongoDB connections using the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.