C# Driver - How to make sure that IAggregateFluent query is performed on database side?

I have a following piece of code in C#:

        IAsyncCursor<Class>? dataCursor = await _mongoCollection.Aggregate()
            .Match(s => s.Id == 1)
                s => new { s.Id },
                g => new Class(
                    g.Max(s => s.Value),
                    g.Average(s => s.Value),
                    g.Min(s => s.Value),
                    g.Sum(s => s.Value),
                    g.Sum(s => s.Value * s.Value)))

        while (await dataCursor.MoveNextAsync())
            foreach (Class? data in dataCursor.Current)
                yield return data;

How can I be sure that the aggregation is executed on Database side?

Hi @Bartosz_Kuriata ,

Welcome to the MongoDB Community Forums! Everything that you have above in the Fluent Aggregate Query will be executed server side. If you use a ToList() or ToListAsync() at the end instead then it would be executed client side. You can even verify the MQL to be executed on the server if you append a ToString() at the end instead of ToCursorAsync() . Hope that helps.