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

Projection fails when expression has field names that are substrings of each other

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Cannot Reproduce
    • Affects Version/s: 2.4.4
    • Fix Version/s: None
    • Component/s: API, Command Operations
    • Labels:
      None
    • Environment:
      Windows .NetStandard 2.0

      Description

      When you have a nested object where there are 2 properties such that the name of the first property starts with the name of the second property.

      public class SubscriberSource
      {
      /// ...
      public DateTime? StatusChangeDate
      { get; set; }
      public SubscriberStatus Status { get; set; }
      }
      
      

      And you try to build a projection, it will not generate anything for the projection at all. There is probably somewhere in the code that a .startsWith is utilized to add fields to the projection builder for some reason.
      So when i write something like

      _collection.Find(query).Project(x => new
      { x.StatusChangeDate, x.Status }
      )
      

      No projection is passed to mongoDb at all and all fields are returned.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              wan.bachtiar Wan Bachtiar
              Reporter:
              vrybak@vertmarkets.com Vadim Rybak
              Participants:
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: