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

Filters in subdocuments can't use fields from the parent document

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.14.0
    • Affects Version/s: 2.4.1
    • Component/s: Linq
    • Labels:
      None
    • Environment:
      ASP.NET Core

      Using a filter via .Where() inside a Select uses the subdocument's value instead of the parent document's.
      i.e:

      // Some comments here
      select new
      {
          Prev = prev.Where(x => x.LastActionTime < visit.FirstActionTime && x.VisitorId != null)
      } into r
      

      Expected result:

      "Prev": {
                      "$filter": {
                          "input": "$prev",
                          "as": "x",
                          "cond": {
                              "$and": [
                                  {
                                      "$lt": [
                                          "$$x.LastActionTime",
                                          "$FirstActionTime"
                                      ]
                                  },
                                  {
                                      "$ne": [
                                          "$$x.VisitorId",
                                          null
                                      ]
                                  }
                              ]
                          }
                      }
                  },
      

      Actual result:

      "Prev": {
                      "$filter": {
                          "input": "$prev",
                          "as": "x",
                          "cond": {
                              "$and": [
                                  {
                                      "$lt": [
                                          "$$x.LastActionTime",
                                          "$$x.FirstActionTime"
                                      ]
                                  },
                                  {
                                      "$ne": [
                                          "$$x.VisitorId",
                                          null
                                      ]
                                  }
                              ]
                          }
                      }
                  },
      

            Assignee:
            james.kovacs@mongodb.com James Kovacs
            Reporter:
            kanadaj Daniel Rusznyak
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: