[CSHARP-1986] And with zero clauses renders as { $and : [] } Created: 19/May/17  Updated: 27/Oct/23  Resolved: 30/May/17

Status: Closed
Project: C# Driver
Component/s: Operations
Affects Version/s: 2.4.3
Fix Version/s: None

Type: Bug Priority: Critical - P2
Reporter: Juan Santander Assignee: Robert Stam
Resolution: Works as Designed Votes: 0
Labels: Bug
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to CSHARP-1291 And and Or filter builder methods sho... Closed

 Description   

Related to CSHARP-1912.
The following code:

var filt1 = Builders<Thing>.Filter.Empty;
var filt2 = Builders<Thing>.Filter.Empty;
var filter = Builders<Thing>.Filter.And(filt1,filt2);

Results in the following filter being rendered:

{ "$and" : [] }

Instead of an empty filter.
This was introduced in version 2.4.2,



 Comments   
Comment by Robert Stam [ 30/May/17 ]

This is by design.

See CSHARP-1291.

Comment by Juan Santander [ 22/May/17 ]

Upon further verification, the issue happens when an empty list is passed to the the And filter, as follows:

List<FilterDefinition<Thing>> filters = new List<FilterDefinition<Thing>>();
var filter = Builders<Thing>.Filter.And(filters);

This results in the wrong filter being rendered:

{ "$and" : [] }

Passing two empty filters renders correctly.

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