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

Find projection of nested field does not compute dotted field name properly

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 2.22.0
    • Affects Version/s: 2.21.0
    • Component/s: None
    • None
    • Fully Compatible
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      Summary

      Driver Version: 2.21.0; No issue up to 2.20.0;

      MongoDB Version: 6.0.10

       

      When projecting a search result to the Id field of a nested document, the top-level Id field is returned.

      See the following (simplified) example.

      Expected: subDocumentId contains the value of the Id field of SubDocument.

      Actual: subDocumentId contains the value of the Id field of Document.

      Up to driver version 2.20.0, this works as expected.

       

      public class BusinessLogic
      {
          public async Task<ObjectId> GetSubDocumentId()
         

      {         var subDocumentId = await _dbContext.Documents.Find(d => d.Status == status)                 .Project(d => d.PairedSwitchingDevice.Id)                 .FirstOrDefaultAsync();         return subDocumentId;     }

      }

      public class Document

      {     [BsonId]     public ObjectId Id \{ get; set; }

          [BsonElement("Status")]
          public string Status { get; set; }

          [BsonElement("SubDocument")]
          public SubDocument SubDocument { get; set; }
      }

      public class SubDocument

      {     [BsonElement("Id")]     public ObjectId Id \{ get; set; }

      }

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            henning.brands@festo.com Henning Brands
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: