This is my first time using MongoDB. I'm using it in an ASP.Net Core project. this is my code:
collection.AsQueryable()
.OrderByDescending(u => u.created_at)
.Skip((page - 1) * perPage)
.Take(perPage)
.ToList();
I'm getting the following error in the controller with no clue in the stack trace:
only fields are allowed in a $sort
only fields are allowed in a $sort mongodb suggests using .ToList()
before sorting. although it works, I don't want just to load the whole table and do the sort in the server.
IQueryable complex order Only fields are allowed in a $sort doesn't apply to me as I'm just using a field to sort.
what is wrong with my Linq query that MongoDB doesn't like?