I have a query like this in mongodb:
db.Product.aggregate([
{ $addFields: { maxSku: { $max: '$ProductVariants.FullSku' } } },
{ $group: { _id: null, value: { $max: '$maxSk' } } }
])
but how can I execute it using mongodb driver (linq) in C#?
I've tried to use db.RunCommandAsync
but that's not working
var command = new JsonCommand<BsonDocument>("db.Product.aggregate([{ $addFields: { maxSku: { $max: '$ProductVariants.FullSku' } } },{ $group: { _id: null, value: { $max: '$maxSk' } } }])");
var result = await _productRepository.Database.RunCommandAsync<BsonDocument(command);
the error is
JSON reader was expecting a value but found 'db'.
at MongoDB.Bson.IO.JsonReader.ReadBsonType()...etc