MongoDb Driver Fields Exclude

3

My problem is this, I have an object:

public class Obj(){
    prop int id {get; set;}
    prop Client client {get; set;}
}

public class Client(){
   prop int id {get; set;}
   prop Group group {get; set;}
}

public class Group(){
   prop int id {get; set;}
}

When doing the query, I would like to return only some values of the object:

var lRetorno = collection.Find(Query.And(query))
                .SetFields(Fields<Obj>.Include(c => c.id, c => c.Client)
                .Exclude(c => c.Client.Group))

Is there a way to return the obj Client without mapping the Group object, without changing the mapping of the class, including?

    
asked by anonymous 20.02.2017 / 16:08

1 answer

1

I do not know C # directly, but what you need to check is the support for your driver's projections.

In the quick tour of the mongo c # driver documentation there is a section on projection, which mentions a Builder of projections. These two places should help you.

    
13.05.2017 / 20:16