[CSHARP-3737] Use $expr when AggregateOptions.Let is specified Created: 12/Jul/21  Updated: 31/Mar/22

Status: Backlog
Project: C# Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: James Kovacs Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to CSHARP-3700 Support 'let' option for aggregate c... Closed

 Description   

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.


Generated at Wed Feb 07 21:46:09 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.