Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-2699

Wrong queries for nested filters

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 2.8.0, 2.8.1, 2.9.0
    • Fix Version/s: 2.9.2
    • Component/s: Linq
    • Labels:
      None
    • Case:

      Description

      The linq expression:

      var list = collection.AsQueryable()
                          .Where(city =>
                              city.Shops.Any(shop => shop.Name == "Shop 1" && shop.Books.Any(book => book.Pages.Any(page => page.Text == "page_1_1"))))
                          .ToList();
      

      Generated queries (from `CommandStartedEvent.ToJson()`)
      v 2.7.3

      aggregate - {
      	"aggregate": "cities",
      	"pipeline": [{
      			"$match": {
      				"Shops": {
      					"$elemMatch": {
      						"Name": "Shop 1",
      						"Books.Pages.Text": "page_1_1"
      					}
      				}
      			}
      		}
      	],
      	"cursor": {},
      	"$db": "test",
      	"lsid": {
      		"id": CSUUID("db90a3a1-e153-44a5-97dd-64660ba367f0")
      	}
      }
      

      v.2.8.0+

      aggregate - {
      	"aggregate": "cities",
      	"pipeline": [{
      			"$match": {
      				"Shops": {
      					"$elemMatch": {
      						"Name": "Shop 1",
      						"Pages": {
      							"$elemMatch": {
      								"Text": "page_1_1"
      							}
      						}
      					}
      				}
      			}
      		}
      	],
      	"cursor": {},
      	"$db": "test",
      	"lsid": {
      		"id": CSUUID("01211669-37e4-4dd3-b838-6efe1a8043ed")
      	}
      }
      

      The `Books` element is missing in query generated by driver v2.8.0+, so it returns wrong result.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                1 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: