Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-1887

Сombine all $match in one $match

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Duplicate
    • Affects Version/s: 2.4.1
    • Fix Version/s: None
    • Component/s: Linq
    • Labels:
      None
    • Environment:
      .NET Core

      Description

      Hi! If I use a lot of expressions "where" we end up with many operators $match. I wish the output was a single operator $match

      Exmaple:

                  if (filter.RoomCounts?.Count > 0)
                  {
                      realEstates = realEstates.Where(r => filter.RoomCounts.Contains(((Room)r.Unit).RoomCount));
                  }
                  if (filter.HouseTypes != null)
                  {
                      realEstates = realEstates.Where(r => filter.HouseTypes.Contains(((Room)r.Unit).HouseType));
                  }
      

      Translate to

              {
                  "$match": {
                      "real_estate_status": {
                          "$in": [
                              1
                          ]
                      }
                  }
              },
              {
                  "$match": {
                      "unit.operation_type": {
                          "$in": [
                              2
                          ]
                      }
                  }
              },
      

      But this is better

                  "$match": {
                      "real_estate_status": {
                          "$in": [
                              1
                          ]
                      },
                      "unit.operation_type": {
                          "$in": [
                              2
                          ]
                      }
                  }
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              rstam Robert Stam
              Reporter:
              boniface Vorobjev Valery
              Participants:
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: