Search code examples
c#.netmongodbmongodb-.net-driverprojection

Server side projection with MongoDB C# driver 2.0


I have a collection of documents with a few small properties, and one huge property (a binary 10MB or so PDF document). I'm using the latest stable C# driver, published on 2015-04-02. Is there a way to get a list of these documents, with all the small properties, but excluding the huge binary one?


Solution

  • You would want to use IFindFluent.Find and then use IFindFluent.Projection and Builders.Projection.Exclude to exclude this property:

    var query = collection.
        Find(filter).
        Project<Document>(Builders<Document>.Projection.Exclude(doc => doc.HugeBlob));
    var results = await query.ToListAsync();