[CSHARP-4802] Find projection of nested field does not compute dotted field name properly Created: 22/Sep/23  Updated: 28/Oct/23  Resolved: 27/Sep/23

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 2.21.0
Fix Version/s: 2.22.0

Type: Bug Priority: Major - P3
Reporter: Henning Brands Assignee: Robert Stam
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by CSHARP-4806 V2.21.0 Projection issue Closed
Backwards Compatibility: Fully Compatible
Documentation Changes: Not Needed
Documentation Changes Summary:

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?


 Description   

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; }

}



 Comments   
Comment by Githook User [ 27/Sep/23 ]

Author:

{'name': 'rstam', 'email': 'robert@robertstam.org', 'username': 'rstam'}

Message: CSHARP-4802: Projection of nested field does not compute dotted field name properly.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/a28da500136d6a61b04e673ae8b0a40ce80b4d1a

Comment by Robert Stam [ 22/Sep/23 ]

I am able to reproduce this. Thanks for reporting it. I'm working on a fix.

Comment by PM Bot [ 22/Sep/23 ]

Hi henning.brands@festo.com, thank you for reporting this issue! The team will look into it and get back to you soon.

Generated at Wed Feb 07 21:49:24 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.