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

The FilterDefinition renders errorneously when Any is used inside another Any operator.

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Critical - P2 Critical - P2
    • 2.3
    • Affects Version/s: 2.2.4
    • Component/s: Linq
    • None
    • Environment:
      Windows 10 x64

      The following code sequence is used to generate the error:

      var documentSerializer = BsonSerializer.SerializerRegistry.GetSerializer<T>();
      var renderedFilter = filterDefinition.Render(documentSerializer, BsonSerializer.SerializerRegistry).ToString();

      The FilterDefinition contains the expression obtained from:

      tours.Where(tour => tour.CarrierAssociations.Any(x => x.CarrierId == myOrganizationId && x.States.Any(y => y.State == TourState.AcceptPending))).ToList();

      The output is:

      { "carrierAssociations" : { "$elemMatch" :

      { "carrierId" : NumberLong(22), "state" : 0 }

      } }

      which is not correct, because "state" is an array of subdocuments, which in turn contain a "state" field. I assume the correct output would have been:

      { "carrierAssociations" : { "$elemMatch" :

      { "carrierId" : NumberLong(22), "state.state" : 0 }

      } }

      or something like that. Note: the "state" names that appear in the JSON are field names specified with the BsonElement attribute, so please do not be confused about them. I don't know exactly which "state" does the output refer to: the "States" collection property, or the "State" within the the elements of this collection - by chance they have the same BSON element name.

      I marked it as critical because we have this problem in production, and we do not have at least a workaround for this. Moreover, we identified this in one place, but we are not sure if the application code contains other similar queries, which we did not identified yet, and which could cause hidden bugs.

            Assignee:
            craig.wilson@mongodb.com Craig Wilson
            Reporter:
            ioan.crisan@soloplan.de Ioan Crisan
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: