I’ve stuck into some weird problem. Here is the code
AccountsController.cs
// GET /api/accounts
[HttpGet]
[Queryable(ResultLimit = 50)]
public IQueryable<AccountDto> Get()
{
return this.service.Get();
}
service here – it’s AccountService.cs
public IQueryable<AccountDto> Get()
{
return this.readModel.Get();
}
and readModel is of type AccountsReadModel
public IQueryable<AccountDto> Get()
{
return Database.GetCollection<AccountDto>("Accounts").AsQueryable();
}
Database is MongoDb.Driver.Database
the problem is following:
when I trying to query Get method without any parameters –
localhost/api/accounts – it returns all accounts (as intended)
when I use skip: localhost/api/accounts?$skip=n – it skips n and returns rest items
(as intended too)
but, localhost/api/accounts?$top=1 returns all accounts, instead of one.
How can I handle it?
The problem was in [Queryable(ResultLimit=50)]:
it and
$top=1together produces following expression:coll.Take(1).Take(50)which returns not 1, but 50 (or all elements in collection, in case if there are less elements than 50).By the way,
Database.GetCollection<A>("A").AsQueryable().Take(1).Take(50)– returns not 1 element again.This looks like bug in MongoDbDriver