Open Closed

Mongodb Searches are case sensitive. Saas Tenant Search #6677


User avatar
0
ndeol@woolworths.com.au created
  • ABP Framework version: 8.0.2
  • UI Type: Angular
  • Database System: MongoDB
  • Tiered (for MVC) or Auth Server Separated (for Angular): yes
  • Exception message and full stack trace:
  • Steps to reproduce the issue:

I am writing to ask about searched implemented in default modules like saas, administration. When using Mongodb they are all case sensitive even for Contains comparison . Which is pretty annoying. When you searching for tenants or user you want searches to be case insensitive as you searching for some partial key and ignore case should be implemented. Have you guys have any work currently pending regrading that. Or if not can you point me to right direction how to implement is globally. This is source code I am referring to which does case sensitive search

public virtual async Task<List<Tenant>> GetListAsync(
        string sorting = null,
        int maxResultCount = int.MaxValue,
        int skipCount = 0,
        string filter = null,
        bool includeDetails = false,
        Guid? editionId = null,
        DateTime? expirationDateMin = null,
        DateTime? expirationDateMax = null,
        TenantActivationState? tenantActivationState = null,
        CancellationToken cancellationToken = default)
    {
        return await (await GetMongoQueryableAsync(cancellationToken))
            .WhereIf<Tenant, IMongoQueryable<Tenant>>(
                !filter.IsNullOrWhiteSpace(),
                u =>
                    u.Name.Contains(filter)
            )
            .WhereIf(editionId.HasValue, tenant => tenant.EditionId == editionId.Value)
            .WhereIf(expirationDateMin.HasValue, tenant => tenant.EditionEndDateUtc >= expirationDateMin.Value)
            .WhereIf(expirationDateMax.HasValue, tenant => tenant.EditionEndDateUtc <= expirationDateMax.Value)
            .WhereIf(tenantActivationState.HasValue, tenant => tenant.ActivationState == tenantActivationState.Value)
            .OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(Tenant.Name) : sorting)
            .As<IMongoQueryable<Tenant>>()
            .PageBy<Tenant, IMongoQueryable<Tenant>>(skipCount, maxResultCount)
            .ToListAsync(GetCancellationToken(cancellationToken));
    }


5 Answer(s)
  • User Avatar
    0
    Anjali_Musmade created
    Support Team Support Team Member

    Hello ,

    Please check this https://stackoverflow.com/questions/4458950/mongodb-and-c-case-insensitive-search try to add ToLower at both side (frontend and backend).

    Thank you.

  • User Avatar
    0
    ndeol@woolworths.com.au created

    I am talking about existing framework code. It seems like I have to override all framework repository for this fix. Tenants, Users administration modules. Do you have any planned work for this ?

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    I will check it.https://github.com/abpframework/abp/issues/19030

  • User Avatar
    0
    ndeol@woolworths.com.au created
    Hello ,
    
    Please check this https://stackoverflow.com/questions/4458950/mongodb-and-c-case-insensitive-search try to add ToLower at both side (frontend and backend).
    
    Thank you.
    

    This solution does not work with Mongodb Linq.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    It works for me:

    protected virtual IQueryable<Book> ApplyFilter(
                IQueryable<Book> query,
                string? filterText = null,
                string? name = null,
                string? title = null)
    {
        return query
            .WhereIf(!string.IsNullOrWhiteSpace(filterText), e => e.Name!.ToLower().Contains(filterText!.ToLower()) || e.Title!.ToLower().Contains(filterText!.ToLower()))
                .WhereIf(!string.IsNullOrWhiteSpace(name), e => e.Name!.ToLower().Contains(name!.ToLower()))
                .WhereIf(!string.IsNullOrWhiteSpace(title), e => e.Title!.ToLower().Contains(title!.ToLower()));
    }
    

Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11