Projection with AsQueryable in MongoDB C# driver 2.2 -
i trying hands @ mongodb c# driver version 2.2. trying use projection not want retrieve elements in document. found 1 way use project operator along find operator, this:
collection.find(key => key.index == 1).project<myclass>(builders<myclass>.projection.include(key => key.name).include(key => key.index)). toenumerable (); however interested in using asqueryable api along operator, this:
collection.asqueryable().where(key => key.index == 1); is possible use projection in above case? if use select operator, have same effect projection? or still fetch elements database server , select specified elements in application server?
yes, possible. if add select (select(i => new { i.name, i.index})) query , call tostring method @ end, you'll see linq provider generates aggregation pipeline 2 operations (a $match , $project):
var query=collection.asqueryable().where(key => key.index == 1).select(k=>new {k.name,k.index}); var aggregate= query.tostring(); in sumary, yes, select generates $project operation.
about other questions, query not going executed until call method tolist (that going fetch result of query memory) or when iterate on result.
Comments
Post a Comment