The above code performs very slow and memory consuming. The problem is that in Projection<TSource, TResult> class the "GetEnumerator()" method don't call _cursor.SetFields() restriction and the complete document was loaded from the database to the client

If we implement it directly with MongoCursor the code looks like this :

CP Digger
added a comment - May 04 2012 08:19:56 AM UTC We would like to have the first option ( 1) simple projection)
In our program we have very large documents (Images) and we want only retrieve the ObjectId's of the document.
IQueryable<ObjectId> queryable = collection.AsQueryable<Image>().OrderByDescending(img => img.Created).Skip(0).Take(15).Select(img => img._id);
The above code performs very slow and memory consuming. The problem is that in Projection<TSource, TResult> class the "GetEnumerator()" method don't call _cursor.SetFields() restriction and the complete document was loaded from the database to the client
If we implement it directly with MongoCursor the code looks like this :
MongoCursor<Image> cursor = collection.FindAll();
cursor.SetSortOrder(SortBy.Descending("Created"));
cursor.SetSkip(0);
cursor.SetLimit(15);
cursor.SetFields(Fields.Include("_id")); // !!! restriction
foreach (Image item in cursor) yield return item._id;