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

Wrong queries for nested filters

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 2.9.2
    • Affects Version/s: 2.8.0, 2.8.1, 2.9.0
    • Component/s: Linq
    • None

      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.

            Assignee:
            dmitry.lukyanov@mongodb.com Dmitry Lukyanov (Inactive)
            Reporter:
            ruslan_shakirov@epam.com Ruslan Shakirov
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: