Eventuous.Projections.MongoDB 0.8.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Eventuous.Projections.MongoDB --version 0.8.0
                    
NuGet\Install-Package Eventuous.Projections.MongoDB -Version 0.8.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Eventuous.Projections.MongoDB" Version="0.8.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Eventuous.Projections.MongoDB" Version="0.8.0" />
                    
Directory.Packages.props
<PackageReference Include="Eventuous.Projections.MongoDB" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Eventuous.Projections.MongoDB --version 0.8.0
                    
#r "nuget: Eventuous.Projections.MongoDB, 0.8.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=Eventuous.Projections.MongoDB&version=0.8.0
                    
Install Eventuous.Projections.MongoDB as a Cake Addin
#tool nuget:?package=Eventuous.Projections.MongoDB&version=0.8.0
                    
Install Eventuous.Projections.MongoDB as a Cake Tool

Eventuous MongoDB projections

This package adds MongoDB projections to applications built with Eventuous.

There are two main components provided by this package:

  • MongoCheckpointStore, implements ICheckpointStore
  • MongoProjection, implements IEventHandler

Using checkpoint store

You can register MongoCheckpointStore so it will be used by all subscriptions that need to store checkpoints (normally, EventStoreDB catch-up subscriptions).

services.AddSingleton<ICheckpointStore, MongoCheckpointStore>();

It will add a checkpoint collection to your Mongo database. Each subscription will have its own checkpoint document. The document id would be the subscription id. Make sure to use unique subscription ids across different applications if they use the same Mongo database.

Using projections

Create your own projection class that inherits MongoProjection<T> abstract class. Here, T is the document type, which must be a record. Your document type should inherit from ProjectedDocument record.

Use the On<TEvent> function to register event projection handlers:

public class ProjectWithTasksProjection : MongoProjection<ProjectWithTasks> {
    public ProjectWithTasksProjection(
        IMongoDatabase  database,
        ILoggerFactory? loggerFactory
    ) : base(database, QuerySubscription.Id, loggerFactory) { 
        On<V1.ProjectRegistered>(
            evt => evt.ProjectId, 
            (evt, update) => update.SetOnInsert(x => x.ProjectName, evt.Name)
        );
        On<V1.TaskCreated>(
            evt => evt.ProjectId,
            (evt, update) => update.AddToSet(
                x => x.Tasks,
                new ProjectTaskRecord(evt.TaskId, evt.Description)
            )
        );
    }
}

There's an overload for On<TEvent> that gives you direct access to the consume context, so you can have more advanced operations.

On<V1.ProjectRegistered>(ctx => { ... });

The function provided as an argument for On in this case needs to return ValueTask<Operation<T>>. To make things easier, we provide a function called UpdateOperationTask.

The UpdateOperationTask function has two overloads. The one used in the example allows passing the document id as the first argument. Another overload allows specifying a custom filter as (filter, evt) => filter.Eq(x => x.Field == evt.Value).

You can also use the UpdateOperation, which allows you to perform asynchronous operations inside the update function.

There is also a handler registration function for building updates asynchronously called OnAsync, which works similar t On:

OnAsync<V1.ProjectRegistered>(
    evt => evt.ProjectId, 
    async (evt, update) => update.SetOnInsert(
        x => x.ProjectName, 
        await getExternalData(evt.Name)
    )
);

You also have an option of not using pre-registered typed handlers by overriding the GetUpdate function. By default it returns NoOp, so if you override it, don't call base.GetUpdate. Eventuous will only call GetUpdate if there's no registered handler for a received event.

The GetUpdate function must return an instance of the Operation<T> record wrapped in ValueTask. UpdateOperation and UpdateOperationTask return ValueTask<UpdateOperation<T>>. You can use one of the supplied record types:

  • UpdateOperation<T> - includes a filter and an update operation
  • CollectionOperation<T> - allows executing any operation on the collection
  • OtherOperation<T> - allows executing anything as it will be just awaited
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Eventuous.Projections.MongoDB:

Package Downloads
Eventuous.Connector.EsdbMongo

Eventuous connector between EventStoreDB and other things

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.15.1 6,111 6 months ago
0.15.0 2,350 8 months ago
0.15.0-rc.3 652 9 months ago
0.15.0-rc.2 1,055 10 months ago
0.15.0-rc.1 683 6/27/2024
0.15.0-beta.10 1,179 2/11/2024
0.15.0-beta.8 480 11/18/2023
0.15.0-beta.7 81 11/17/2023
0.15.0-beta.6 1,322 10/4/2023
0.15.0-beta.5 3,569 8/28/2023
0.15.0-beta.4 345 8/22/2023
0.15.0-beta.3 82 8/21/2023
0.15.0-beta.2 90 8/21/2023
0.15.0-beta.1 384 8/21/2023
0.14.0 25,552 2/10/2023
0.13.4-alpha.0.1 132 2/10/2023
0.13.3 858 2/1/2023
0.13.2 302 2/1/2023
0.13.1 1,398 1/14/2023
0.13.0 765 1/10/2023
0.12.0 759 10/6/2022
0.11.4 423 9/30/2022
0.11.3 463 9/27/2022
0.11.2 583 9/23/2022
0.11.1 466 9/23/2022
0.11.0 457 9/20/2022
0.10.6 528 9/9/2022
0.10.5 473 8/25/2022
0.10.4 437 8/22/2022
0.10.3 449 8/21/2022
0.10.2 1,586 7/20/2022
0.10.1 478 7/20/2022
0.10.0 484 7/17/2022
0.9.1 486 6/24/2022
0.9.0 475 6/15/2022
0.8.4 526 5/18/2022
0.8.3 534 5/11/2022
0.8.2 460 5/11/2022
0.8.1 520 5/8/2022
0.8.0 458 4/25/2022
0.7.1 525 4/21/2022
0.7.0 486 4/13/2022
0.6.2 472 3/28/2022
0.6.1 473 3/11/2022
0.6.0 1,256 2/21/2022
0.6.0-rc.8 272 11/27/2021
0.6.0-rc.7 2,451 11/25/2021
0.6.0-rc.6 3,303 11/25/2021
0.6.0-rc.5 3,028 11/25/2021
0.6.0-rc.4 4,964 11/24/2021
0.6.0-rc.3 4,878 11/23/2021
0.6.0-rc.2 1,130 11/20/2021
0.6.0-rc.1 193 11/19/2021
0.5.15 5,746 10/12/2021
0.5.14 831 10/10/2021
0.5.13 345 10/10/2021
0.5.12 401 10/10/2021
0.5.11 415 10/10/2021
0.5.10 416 10/10/2021
0.5.9 553 10/9/2021
0.5.8 365 10/9/2021
0.5.7 359 10/9/2021
0.5.6 343 10/9/2021
0.5.5 400 10/9/2021
0.5.4 424 10/9/2021
0.5.3 405 10/9/2021
0.5.2 448 10/9/2021
0.5.1 377 10/6/2021
0.5.0 457 10/5/2021
0.4.7 917 8/20/2021
0.4.6 481 8/6/2021
0.4.5 780 6/4/2021
0.4.4 1,197 5/25/2021
0.4.3 388 5/24/2021
0.4.2 404 5/24/2021
0.4.1 460 5/21/2021
0.4.0 408 5/21/2021
0.3.1 411 5/24/2021
0.3.0 369 5/12/2021
0.2.0 433 4/27/2021
0.1.1 431 4/9/2021
0.1.1-alpha.0.9 204 4/8/2021
0.1.1-alpha.0.7 202 4/8/2021
0.1.1-alpha.0.6 203 4/8/2021
0.1.1-alpha.0.5 191 3/29/2021
0.1.0 448 3/25/2021
0.0.0-alpha.0.41 182 3/24/2021
0.0.0-alpha.0.31 214 3/24/2021
0.0.0-alpha.0.22 223 3/24/2021
0.0.0-alpha.0.21 229 3/23/2021
0.0.0-alpha.0.20 235 3/23/2021
0.0.0-alpha.0.19 234 3/23/2021
0.0.0-alpha.0.18 184 3/17/2021
0.0.0-alpha.0.17 178 3/17/2021
0.0.0-alpha.0.16 178 3/17/2021
0.0.0-alpha.0.15 191 3/17/2021
0.0.0-alpha.0.14 191 3/17/2021
0.0.0-alpha.0.13 211 3/16/2021
0.0.0-alpha.0.12 218 3/10/2021
0.0.0-alpha.0.11 250 3/10/2021
0.0.0-alpha.0.10 249 3/10/2021
0.0.0-alpha.0.9 256 3/8/2021
0.0.0-alpha.0.8 198 3/8/2021