Mongo c# driver generate different Query for 2.14.1 -- 2.23.1 version

Hello

Below code block generates different queries for different driver versions - 2.14.1 – 2.23.1:
What is the problem, is a kind of Bug for Mongo DB driver?

Code Block:

_transactionRepository.GetCollection()
            .Aggregate()
            .Match(filterQuery)
            .Project<TransactionsReportProjections.OrderTransactionProjection>(
                Builders<TransactionEntity>.Projection
                    .Include(p => p.Data.FoodOrders)
                    .Exclude(p => p.Id))
            .Unwind<TransactionsReportProjections.OrderTransactionProjection, TransactionsReportProjections.OrderTransactionUnwind>(u =>
                u.Data.FoodOrders)
            .Group(g => string.Empty, f => new TransactionsReportProjections.FoodOrder
            {
                FoodOrders = f.Select(s => s.Data.FoodOrders)
            })
            .Project<TransactionsReportProjections.FoodOrder>(
                Builders<TransactionsReportProjections.FoodOrder>.Projection.Include(p => p.FoodOrders))
            .Unwind<TransactionsReportProjections.FoodOrder, TransactionsReportProjections.OrderTransactionUnwindGroupFoodOrder>(u =>
                u.FoodOrders)
            .Group(g => g.FoodOrders, f => new TransactionsReportProjections.OrderTransactionUnwindFoodOrder
            {
                FoodOrders = f.Key
            });

Query of Mongo Driver 2.14.1 version:

  [
   {
      $match: {
        restaurant: {
          $in: [
            ObjectId("60b652278609c47130356c00")
          ],
        },
        type: { $ne: 1 },
        orderDay: {
          $gte: "2024-01-09",
          $lte: "2024-02-09",
        },
      },
    },
    { $project: { "data.foodOrders": 1, _id: 0 } },
    { $unwind: "$data.foodOrders" },
    {
      $group: {
        _id: "",
        FoodOrders: { $push: "$data.foodOrders" },
      },
    },
    { $project: { FoodOrders: 1 } },
    { $unwind: "$FoodOrders" },
    { $group: { _id: "$FoodOrders" } },
  ]

Query of Mongo Driver 2.23.1 version:

[
    {
      $match: {
        restaurant: {
          $in: [
            ObjectId("60b652278609c47130356c00")
          ],
        },
        type: { $ne: 1 },
        orderDay: {
          $gte: "2024-01-09",
          $lte: "2024-02-09",
        },
      },
    },
    { $project: { "data.foodOrders": 1, _id: 0 } },
    { $unwind: "$data.foodOrders" },
    {
      $group: {
        _id: "",
        __agg0: { $push: "$data.foodOrders" },
      },
    },
    { $project: { foodOrders: "$__agg0", _id: 0 } },
    { $project: { foodOrders: 1 } },
    { $unwind: "$foodOrders" },
    { $group: { _id: "$FoodOrders" } },
  
    { $project: { foodOrders: "$_id", _id: 0 } },
]

Hi, @Hamdi_Bayhan,

Thank you for reaching out to us about the changes in your resulting MQL. The 2.14.1 driver uses our LINQ2 implementation by default whereas 2.23.1 uses the newer LINQ3 implementation by default. Although you’re using the Fluent Aggregate API, we internally use LINQ to translate lambdas in the query translation process.

While the MQL and resulting shape of the query results are slightly different between the two LINQ providers, I don’t see an immediate problem with these differences. Is this resulting in incorrect query results or an exception on deserialization? If so, please file a https://jira.mongodb.org/browse/CSHARP ticket with a self-contained repro so that we can investigate further. It would be helpful to have all the associated class definitions such as FoodOrder, OrderTransactionProjection, and similar so we can debug through the code.

Sincerely,
James

Thank you James for the fast and detailed replay. Yes result is different, I will create a ticket in JIRA.

This is JIRA task for this topic: https://jira.mongodb.org/browse/CSHARP-4964