Home > OS >  SetSkip method in MongoDB driver C#
SetSkip method in MongoDB driver C#

Time:09-17

What is an alternative for SetSkip method in MongoDB driver 2.17 in C#. Before it was used for pagination and old code was like:

GetCollection(GetCollectionName(collectionName), federatedDBKey)
                .Find(query)
                .SetSkip((pageNumber - 1) * pageSize)
                .SetLimit(pageSize)
                .SetSortOrder(sort)
                .AsQueryable();

I don't know how to rewrite this in new version as this method is now part of MongoDB.Driver.Legacy.

CodePudding user response:

Instead of using SetSkip, you can use Skip and so on:

GetCollection(GetCollectionName(collectionName), federatedDBKey)
            .Find(query)
            .Skip((pageNumber - 1) * pageSize)
            .Limit(pageSize)
            .SortOrder(sort)
            .AsQueryable();
  • Related