[CSHARP-3298] PipelineDefinitionBuilder.Match() method generates incorrect BsonDocument for equality filter Created: 02/Jan/21 Updated: 27/Oct/23 Resolved: 07/Jan/21 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | BSON, Builders |
| Affects Version/s: | 2.11.5 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Marwan Aouida | Assignee: | Dmitry Lukyanov (Inactive) |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Windows/ASP.NET Core 3 |
||
| Description |
|
I have the following code: PipelineDefinitionBuilder.Match<BsonDocument, BsonDocument>(myPipeline, Builders<BsonDocument>.Filter.Eq("$_id", "$$userId")); I expect the generated BsonDocument to be: {{ { "$eq": ["$_id", "$$userId"] }}} Instead I get this: {{ { "$_id": "$$userId" }}} Which results in the aggregation command to fail with error: Command aggregate failed: unknown top level operator: $_id Other filters seems to work as expected. e.g PipelineDefinitionBuilder.Match<BsonDocument, BsonDocument>(myPipeline, Builders<BsonDocument>.Filter.Gt("$var1", "$$var2")); Generates: {{ { "$gt": ["$var1", "$$var2"] }}} |
| Comments |
| Comment by Dmitry Lukyanov (Inactive) [ 07/Jan/21 ] | |||
|
Hello marwan@aouida.com , The issue is related to the fact that you use $_id with a dollar sign. This syntax for referencing fields is not valid in this context. The right form should be with simple _id key. Also, you cannot use variable with $$ in such context, this method allows using only constants in TField value. So, this query will work:
|