-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Builders
-
None
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Cluster: Standalone
Edition: MongoDB 5.0.9 Community
Summary
Using the C# driver and LINQ Fluent Find, I'm not able to project only certain properties of an array.{}
How to reproduce
Let's say I have this data in my database:
{
"_id": {
"$oid": "62baf9a2851424fdb8c226f8"
},
"Name": "Team A",
"TeamData": {
"Players": [
{
"FirstName": "First Name A",
"LastName": "Last Name A"
},
{
"FirstName": "First Name B",
"LastName": "Last Name B"
}
]
}
}
Using LINQ Fluent Find, I can't select an object containing only "LastName". By using this code:
var result = coll.Find("{}") .Project(x => x.TeamData.Players.Select(c => c.LastName)) .ToList()
The generated request for this ends up being:
{
"find": "coll",
"filter": {},
"projection": {
"Players.LastName": 1,
"TeamData.Players": 1,
"_id": 0
}
}
...which selects all of "Players" properties.
Directly inputting the json works, but is not the desired way:
var result = coll.Find("{}") .Project("{ 'TeamData.Players.LastName': 1 }") .ToList();
Additional Background
This spawned a question here.