-
Type: New Feature
-
Resolution: Unresolved
-
Priority: 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.
- related to
-
CSHARP-3700 Support 'let' option for aggregate command
- Closed