[CSHARP-1638] MongoDB Driver 2.2.3 IMongoCollection paging Created: 26/Apr/16  Updated: 05/Apr/19  Resolved: 16/May/16

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 2.2.3
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Bilgehan Assignee: Unassigned
Resolution: Done Votes: 0
Labels: question
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Hi,
I upgrade my driver to 2.2.3
In my previous version I use,

MongoCollection.AsQueryable<TEntity>().Skip(skip).Take(count); 

I can query with database pagination with MongoCollection.

new driver I change it to IMongoCollection

IMongoCollection.AsQueryable<TEntity>().Skip(skip).Take(count)

{aggregate([{ "$skip" : 0 }, { "$limit" : 10 }, { "$match" : { "Name" : "a" } }])}

For example
with this query (I want to take 10 record) It get first ten records and then if two of them matches I get two record as a result.

But I want to get first ten records which Name is a,and with this I can make database pagination.With old driver I brings first ten records which matches a,What should I do to achive database pagination in new driver with IMongoCollection

Thanks



 Comments   
Comment by Bilgehan [ 27/Apr/16 ]

Hi Craig

You are right,I can able to do that change query

{aggregate([{ "$match" :

{ "Name" : a }

},

{ "$skip" : 40 }

,

{ "$limit" : 10 }

])} ,

As I see implementation is change in new driver I can use as I said in previous version.

I change my code

Thanks for your help

Comment by Craig Wilson [ 26/Apr/16 ]

Hi Bilgehan,

Queryable's are order sensitive. In other words, if you do a Skip and Take before a Where, then that's the order in which things are going to happen. Hence, you need to add your paging information at the end, right before execution as opposed to at the beginning.

AsQueryable().Where(x => x.Name == "a").Skip(0).Take(10);

Let me know if this needs further explanation.
Craig

Generated at Wed Feb 07 21:40:14 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.