It is possible to do range based pagination with mongo linq or I'm better off with filter
route. The following is my case at hand:
I store and generate by Id's as mongo ObjectId
s, but treat them as strings
in my domain:
BsonIgnoreIfDefault]
[BsonRepresentation(BsonType.ObjectId)]
[BsonId(IdGenerator = typeof(StringObjectIdGenerator))]
public string Id { get; set; }
and I'm trying
var result = await _collection.AsQueryable()
.Where(m => m.Id > afterId) // '>' illegal with strings
.OrderBy(m => m.Id)
.ToListAsync();
Error CS0019 Operator '>' cannot be applied to operands of type 'string' and 'string'
.
Another option. My Id's are mongo-generated as ObjectId
and I compare them in my filter:
var idFilter = Builders<T>.Filter.Gt(m => m.Id, afterId);
result = await _collection.Find(idFilter).ToListAsync();