MongoDB.Bson MongoDB.Driver MongoDB.Driver.Core Newtonsoft.Json MongoDB.Bson MongoDB.Bson.Serialization.Attributes MongoDB.Bson.Serialization.Attributes MongoDB.Driver System System.Collections.Generic System.Diagnostics System.Linq System.Text System.Threading.Tasks System.Dynamic async Task Main() { string msg = @"{ ""PayrollId"":463236,""Message"":""Fine"",""Success"":true,""MessageCode"":200,""IsError"":false }"; dynamic details = Newtonsoft.Json.JsonConvert.DeserializeObject(msg); var data = new DomainEventData() { AggregateId = Guid.NewGuid(), TenantId = Guid.NewGuid(), AggregateName = "Just a test", EventName = "payrollunit-schedule-missed", Details = details }; MongoClient client = new MongoClient("mongodb://localhost/tests"); IMongoDatabase mongo = client.GetDatabase("tests"); IMongoCollection items = mongo.GetCollection("entries"); await items.InsertOneAsync(data); } // Define other methods and classes here [Serializable] public class DomainEventData { public Guid Id { get; set; } [BsonElement("eventName")] public string EventName { get; set; } [BsonElement("tenantId")] public Guid TenantId { get; set; } [BsonElement("aggregateId")] public Guid AggregateId { get; set; } [BsonElement("aggregateName")] public string AggregateName { get; set; } [BsonElement("details")] public dynamic Details { get; set; } [BsonElement("utcTimestamp")] [BsonDateTimeOptions(Kind = DateTimeKind.Utc)] public DateTime UtcTimestamp { get; set; } public DomainEventData() { this.Id = Guid.NewGuid(); this.TenantId = Guid.Empty; this.AggregateId = Guid.Empty; this.EventName = string.Empty; this.UtcTimestamp = DateTime.UtcNow; this.AggregateName = string.Empty; } }