mongodb c# select specific field - Stack Overflow
stackoverflow.com › questions › 31143586Jun 30, 2015 · Viewed 11k times. 4. Need some help creating a generic method for selecting fields by their name. something like this: T GetDocField<T> (string doc_Id, string fieldName) The best I got is using projection which gives me the doc with only the wanted field seted: public T GetDocField<T> (string Doc_Id, string fieldName) { var value = DocCollection.Find (d => d.Id == Doc_Id) .Project<T> (Builders<Doc>.Projection .Include (new StringFieldDefinition<Doc> (fieldName))).FirstOrDefaultAsync ().