craiggwilson/fluent-mongo — Issue #33: Advanced Pagination
Author: YakupIpek
Created: 2011-11-07 17:35:51+00:00
State: open

MongoDb supports pagination in array properties so i wanted to query Post with paginated comments. I am sure that this scenario is not possible with fluent mongo but it should to be really.

I am aware that it is a little bit harder to write such a query by linq because i have not seen any such a linq query till now so i started to think how i can write it . Below query can be candidate

query.Where(post => post.Id == id).Select(post=> new Post
{
Comments = post.Comments.Skip(page * pageSize).Take(pageSize)
}).Single();

I actually need to more advanced query which include Comments Count.

query.Where(post => post.Id == id).Select(post => new
{
CommentsCount = post.Comments.Count(),
Post = new Post { Comments = post.Comments.Skip(page*pageSize).Take(pageSize) }
}).Single();

Best way to handle such a queries must be similar to Entity Framework's Include Extensions methods like below

mongoQuery.Include( post=>post.comments.skip(10).take(10) ).SingleOrDefault(post => post.Id == id).Select(post=> new
{
Post = post,
CommentCount = post.Comments.Count()
}).Single();

FluentMongo would be delicious with these query capabilities.