In addition for my previous question: mongodb c# select specific field.
I'm writing a generic method for selecting a specific field.
the requirements are:
- Field can be of any type
- Return type is T
- Field can be inside a sub field
- Field can be inside array items - in that case its OK to select the specific field of all the items in the array
for shorts, im looking for the "select" / dot notation capability. for example:
the wanted method:
T GetFieldValue<T>(string id, string fieldName)
the document:
persons
{
"id": "avi"
"Freinds" : [
{
"Name" : "joni",
"age" : "33"
},
{
"Name" : "daniel",
"age" : "27"
}]
}
The goal is to call the method like this:
string[] myFriends = GetFieldValue<string[]>("avi", "Freinds.Name");
myFriends == ["joni","daniel"]
as far as i know, using projection expression with lambda is no good for items in array, I was thinking more dot notation way.
note: I'm using the new c# driver (2.0)
Thanks A lot.