0
dev3.advantiss created
- ABP Framework version: v5.3.3
- UI Type: Angular
- Database System: MongoDB
Hello
I have found some code with query(It did not work in CosmosDB):
namespace Volo.Abp.PermissionManagement.MongoDB;
public class MongoPermissionGrantRepository : MongoDbRepository<IPermissionManagementMongoDbContext, PermissionGrant, Guid>,
IPermissionGrantRepository
{
public MongoPermissionGrantRepository(IMongoDbContextProvider<IPermissionManagementMongoDbContext> dbContextProvider)
: base(dbContextProvider)
{
}
public virtual async Task<PermissionGrant> FindAsync(
string name,
string providerName,
string providerKey,
CancellationToken cancellationToken = default)
{
cancellationToken = GetCancellationToken(cancellationToken);
return await (await GetMongoQueryableAsync(cancellationToken))
**.OrderBy(x => x.Id)**
.FirstOrDefaultAsync(s =>
s.Name == name &&
s.ProviderName == providerName &&
s.ProviderKey == providerKey,
cancellationToken
);
}
MongoDB get next query:
"aggregate":"AbpPermissionGrants",
"pipeline":[
{
"$match":{
"TenantId":null
}
},
{
"$sort":{
"_id":1
}
},
{
"$match":{
"Name":"Dibl.Themes.View",
"ProviderName":"R",
"ProviderKey":"Facilitator"
}
},
Why did you use OrderBy(x => x.Id) in this query? And I think "$sort" hurts query performance...
Best regards, Advantiss Inc
1 Answer(s)
-
0
hi
The query uses the 'First'/'FirstOrDefault' operator without 'OrderBy' and filter operators. This may lead to unpredictable results.
This is the reason that we use
orderby
.