Skip and limit issues (Cosmos DB - mongo) RRS feed

  • Question

  • Hello,

    I'm currently working with a CosmosDB and I have to paginate some extractions with the Mongo API.

    I'm using a skip and a limit to perform that, here is how it looks like:

    db.getCollection('myCollection').find({}).sort({ sortKey: -1 }).skip(0).limit(25)

    My issue is that I have some duplicates as I'm increasing the skip and the limit, so, for this:

    db.getCollection('myCollection').find({}).sort({ sortKey: -1 }).skip(25).limit(25)

    I have some documents that were already in the first extraction (and I don't have any duplicates in my database). I tried with the aggregate framework and with a regular mongo database filled with same documents and it seems to work well.

    Am I doing something wrong? Or is this is known bug?

    Thanks in advance

    Monday, May 11, 2020 10:20 PM

All replies

  • Hi Stephen,

    Can you detail which version of the Azure Cosmos DB MongoDB API you are working with? If you have version 3.6 deployed, please ensure you are using the 3.6 endpoint (.mongo.cosmos.azure.com) and not the Mongo 3.2 endpoint (.documents.azure.com).

    If you have version 3.6 deployed and are calling the 3.6 URI, can you provide a more complete example so that I can potentially escalate this. 



    Tuesday, May 12, 2020 10:58 PM
  • Hi Stephen,

    Did you get this issue resolved or are you still looking for a resolution? If you found a resolution, can you please share that so as to help others who might be experiencing the same issue. If you need further assistance, can you please let us know so we can help you resolve this.

    Thank you,


    Tuesday, May 26, 2020 1:59 AM
  • Hello Mike,

    I did not find a solution, we are currently using a 3.4 mongodb API and working on the migration to 3.6. I hope it will solve our issues.

    Tuesday, May 26, 2020 9:28 AM
  • Stephen,

    You could run test where you deploy version 3.6 of the Azure Cosmos DB for MongoDB API, load a sample of your data, and run the client operations to test if the same behavior is present in version 3.6. If the issue is fixed, then you will have confirmation. There are a couple options to upgrade:

    You mention version 3.4 and I am not sure where is coming from, as Azure Cosmos DB for MongoDB API is available in versions 3.2 and 3.6.



    Monday, June 1, 2020 6:38 PM