Start a new topic

Problems with skip and limit?

Hello all,

Some time ago (maybe a year ago) I implemented the skip and limit stuff on my queries to the database. Currently the iPhone app should be getting 20 out at a time. When you scroll to the bottom this activates getting more. This was working fine up since I coded in and these particular queries have been the same for some time as well. The version of the sdk I think is 1.25.0 or some where around there.

Well about a month ago our web app which was doing basically the same thing started to have issues with getting more places using the skip and limit. In this case you hit a button called get more and it would return nothing was found. At first we just pushed it off as a bug somewhere and did not worry about it for the most part. (It was still in beta and has some bugs that had higher priority) Not sure what version the sdk is or how the skip and limit are being used.

As a side note we are working on a java version to using the java api that kinvey made and we are having issues as well.

Anyway, long story short we come to find out that my iPhone app is doing the same thing. When you scroll to the bottom of the screen it informs you that there is no more to get. When this is not the case. I get no error code or message. I am not even sure how to approach the issue. Since I am not getting and errors I have no idea how to trouble shoot it.

Have you guys changed anything about the skip and limit on queries?

Is anyone else having these issues?

Any suggestions on where to go from here?



What does your query look like?
This is the iOS code.

I am not sure how to check what version of the sdk I am using. I know it is not 1.26, I believe it is 1.25.

Below is the code. So if skip is 0 and the limit is 20 if gives me what i expect. It goes to the database and gets 20 items out of the database. Everything works as expected. Errors is nil, object has an array with 20 items. As soon as I set skip to 20 and limit to 20 this is where I have problems. It will go to teh database and give me back an array. The array will have 0 items in it though. Errors will still be nil. The collection is our places collection. Not sure whats going on with it.



* This function will go get places objects based off of the current location and the channel name.

* if there is no channel name then it will jsut do location. This will us skip and limit modifers

* to make sure that it only gets a certain amount of objects each time aka 20 and it can skip a

* certain amount if needed.


-(void) callToDatabaseOnPlaceCollectionUsingCurrentLocationWithSkip: (int) skip

withSkipLimit: (int) skipLimit

withChannelQueryName: (NSString *) channelName

withDelegate: (id) delegate {

//pointer to a query

KCSQuery *geoQuery = nil, *mutiQuery = nil, *channelQuery = nil;

KCSAppdataStore *placesStore = [KCSAppdataStore storeWithOptions:@{ KCSStoreKeyCollectionName : placesCollection,

KCSStoreKeyCollectionTemplateClass : [Place class]}];

geoQuery = [KCSQuery queryOnField:KCSEntityKeyGeolocation


forValue:@[@(currentLocation.coordinate.longitude), @(currentLocation.coordinate.latitude)]];

if (channelName != nil) {

//setup the compound query

channelQuery = [KCSQuery queryOnField:@"channels" withRegex:channelName];

mutiQuery = [[KCSQuery alloc] init];

[mutiQuery addQuery:geoQuery];

[mutiQuery addQuery:channelQuery];


//set the skip amount, and limit amount

(mutiQuery == nil ? geoQuery : mutiQuery).limitModifer = [[KCSQueryLimitModifier alloc] initWithLimit:skipLimit];

(mutiQuery == nil ? geoQuery : mutiQuery).skipModifier = [[KCSQuerySkipModifier alloc] initWithcount:skip];

//send the request to the database.

[placesStore queryWithQuery:mutiQuery == nil ? geoQuery : mutiQuery

withCompletionBlock:^(NSArray *objectsOrNil, NSError *errorOrNil){

if ([delegate respondsToSelector:@selector(databaseCallDidFinishWithObjects:withErrors:isUpdate:)]) {

[delegate databaseCallDidFinishWithObjects:objectsOrNil withErrors:errorOrNil isUpdate: skip == 0 ? true : false];


} withProgressBlock:^(NSArray *objects, double percentComplete) {

//NSLog(@"progress = %f", percentComplete);



Permissions on the collection are full at the moment. If it is on full it should not matter what user can access it?

I have put nslog statements throughout the app to try to find the case of the issues. Everything is where it should be as far as what the variables should be. I am just getting nothing back from the database.

Just as a side note the last time the code had been changed was back in February. It was working about a month ago.


Hi All, Any solution to this issue. I am facing exact same issue when using geolocation. For simple queries the limit works fine but for geo location queries i am facing exact issue. Any help/solution would be appreciated. Azeem
I was able to reproduce with the REST API, so this is either a bug or a limitation in our system. I will check with our Mongo guys.
Hi Sean,

It seems you've hit a bug in our underlying database that came into place when we upgraded to the latest version a little under a month ago. Basically, when using skip and limit with geoqueries, the limit is applied before the skip. For example, if your geoquery would return the documents [a, b, c, d], your skip value is 2, and your limit is 3, the database will return [c] (first limiting to 3, and then skipping the first 2 results). We will work on a patch on our end, but until then, I hope this information will help you create a workaround (for example, by adding the skip amount to the limit).
Thanks..Can u Please update me when u get anything is this is kind of urgent issue for us . Appreciate ur prompt response. Azeem
So I am working with some Kinvey people to get a eta on the time frame for a fix. Not sure what it is going to be yet but in the mean time you can fix it yourself if it is causing major issues.

So for reference, you would need to add the limit amount to your skip to get it to work right. For example, in my code I pull out 20 items and then I pull out the next 20 items. For this to work with the current bug my code would need to change to this:

'//So this is the part I change. The reason for the change is explained below

skipLimit = skipLimit + skip;

//set the skip amount, and limit amount

geoQuery.limitModifer = [[KCSQueryLimitModifier alloc] initWithLimit:skipLimit];

geoQuery.skipModifier = [[KCSQuerySkipModifier alloc] initWithcount:skip];`

In a nut shell the database is applying the limit before it skips. If you tell it to skip 20 and limit it to 20 then it will limit the results to the first 20 items no matter the skip. But if i limit it to 40 items and I skip 20 we will get the last 20 back. Another way to say it is the limit always starts from 0 instead of the skip amount. Hope this makes since. So if you want to skip 60 and only pull out 20 more items then skip would be 60 and limit would be 80.... 80 - 60 would give you the 20 items you need. Keep in mind this only is the case for geoqueries all other queries would the usual way. Aka if you want to skip 60 and pull out 20 then skip would be 60 and limit would be 20.

If you have any questions I can try to help. Hopefully though a fix will be on the road map pretty fast.



Word is a fix sound be out by the end of the month.
"Hi Sean,

The fix is out as of a couple of days ago. Can you confirm things work as expected?


Ivan Stoyanov

VP of Engineering "

The fix is out and confirmed working for who ever was having issues. This is now closed.
Login or Signup to post a comment