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

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Gone away
    • Priority: Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • Dotnet Drivers
    • None
    • None
    • None
    • None
    • None
    • None

      Hello, today I upgraded Mongo driver from 2.14.1 to 2.23.1. 
      Then I noticed new MongoDB generated a different query. New version MongoDB query result is null.

      Code Blocks and Generated Queries & Result at the below:

      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
                  });  

      Generated Query via 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" } },
        ]

       

      Result:

      {   "_id": { "$oid": "65ba40bb92bc7771fc876c05" } }

      Generated Query via 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 } },
      ]
      

       

      Result:

      {
        "foodOrders": null
      }

       

       

      _Example TransactionEntity Data:_

      {
        "_id": {
          "$oid": "65c40cca5a2f91756eacfaee"
        },
        "createdAt": {
          "$date": "2024-02-07T23:05:46.221Z"
        },
        "updatedAt": {
          "$date": "2024-02-07T23:05:46.221Z"
        },
        "createdAtL": {
          "$date": "2024-02-08T02:05:46.221Z"
        },
        "restaurant": {
          "$oid": "60b652278609c47130356cfd"
        },
        "data": {
          "foodOrders": [
            {
              "$oid": "65c23d12b9b91421b70d46er"
            },
            {
              "$oid": "65c23cd3a794ee02848ba44f"
            }
          ]
        },
        "orderDay": "2024-02-07",
        "type": 3,
      
      } 

            Assignee:
            Robert Stam
            Reporter:
            Hamdi Bayhan
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: