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

Use $expr when AggregateOptions.Let is specified

    • Type: Icon: New Feature New Feature
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None

      The following query returns no results because it is querying for the literal value $$surname, not the value of the variable specified in AggregateOptions.Let:

      var query = coll.Aggregate(new AggregateOptions {Let = new BsonDocument{{ "surname", "Smith"}}})
                      .Match(x => x.LastName == "$$surname");
      

      In order to query for the value of the $$surname variable you must use $expr. So the correct query is:

      var query = coll.Aggregate(new AggregateOptions {Let = new BsonDocument{{ "surname", "Smith"}}})
                      .AppendStage<Person>(
                          new BsonDocument {{ "$match",
                              new BsonDocument {{
                                  "$expr", new BsonDocument {{ "$eq", new BsonArray {"$LastName", "$$surname"} }}
                              }}
                          }});
      

      If AggregateOptions.Let is provided, the driver should render expressions using the variable with $expr. For example, the Match in the first example should render something akin to the second example automatically.

            Assignee:
            Unassigned Unassigned
            Reporter:
            james.kovacs@mongodb.com James Kovacs
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: