EventFlow icon indicating copy to clipboard operation
EventFlow copied to clipboard

Add an overload to `IMongoDbReadModelStore<TReadModel>.FindAsync()` for custom Queries

Open Herlitzd opened this issue 5 years ago • 0 comments

Linq To mongo doesn't support most methods for working with collections. For instances, something like:

    public class SomeQuery : IQuery<IEnumerable<MyReadModel>>
    {
        public SomeQuery (IEnumerable<Reference> references)
        {
            References = references;
        }

        public IEnumerable<Reference> References { get; }
    }
        public async Task<IEnumerable<MyReadModel>> ExecuteQueryAsync(SomeQuery query, CancellationToken cancellationToken)
        {
            var cursor = await ReadModelStore.FindAsync(x => query.References.Any(z => z.ReferenceNumber == x.ReferenceNumber),
                    cancellationToken: cancellationToken);
            var results = await cursor.ToListAsync();
            return results;
        }

Will not work, the Mongo Driver will report that a method is not supported, presumably the .Any().

Ideally, an overload for FindAsync() would be added to the IMongoDbReadModelStore<TReadModel> interface to allow for the passing of a Mongo Query constructed with Builders<MyReadModel>.Filter and so on.

I am happy to submit a PR, but wanted to make sure that there wasn't a reason to not expose that overload to begin with.

Herlitzd avatar Jan 05 '21 19:01 Herlitzd