Get summation of all field in mogofb c#

Viewed 40

I have a mongodb which looks like this

[
{
    "client_id": "abc",
    "product_id": "123",
    "weight": {
        "value": 100
        "unit": "kg"
    }
},
{
    "client_id": "def",
    "product_id": "456",
    "weight": {
        "value": 200
        "unit": "kg"
    }
}
]

I need to get summation of weight value for a certain client id and product id using mongodb c# client, how can I do that?

I tried this but it is always returning 0

var total_weight = await Collection.AsQueryable()
                        .Where(
                        x => x.client_id == "abc" &&
                        x => x.product_id== "123")
                        .SumAsync(x => x.weight.value);

Thanks

0 Answers
Related