[CSHARP-1887] Сombine all $match in one $match Created: 08/Jan/17  Updated: 11/Jan/17  Resolved: 11/Jan/17

Status: Closed
Project: C# Driver
Component/s: Linq
Affects Version/s: 2.4.1
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Vorobjev Valery Assignee: Robert Stam
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

.NET Core


Issue Links:
Duplicate
duplicates CSHARP-1838 Merge multiple .Where() clauses to a ... Closed

 Description   

Hi! If I use a lot of expressions "where" we end up with many operators $match. I wish the output was a single operator $match

Exmaple:

            if (filter.RoomCounts?.Count > 0)
            {
                realEstates = realEstates.Where(r => filter.RoomCounts.Contains(((Room)r.Unit).RoomCount));
            }
            if (filter.HouseTypes != null)
            {
                realEstates = realEstates.Where(r => filter.HouseTypes.Contains(((Room)r.Unit).HouseType));
            }

Translate to

        {
            "$match": {
                "real_estate_status": {
                    "$in": [
                        1
                    ]
                }
            }
        },
        {
            "$match": {
                "unit.operation_type": {
                    "$in": [
                        2
                    ]
                }
            }
        },

But this is better

            "$match": {
                "real_estate_status": {
                    "$in": [
                        1
                    ]
                },
                "unit.operation_type": {
                    "$in": [
                        2
                    ]
                }
            }



 Comments   
Comment by Robert Stam [ 11/Jan/17 ]

The server already performs this optimization so it is not necessary for the drivers to do so also.

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