Search code examples
azureazure-cosmosdbazure-cosmosdb-mongoapi

CosmosDB Mongo v.4.0 throws Query exceeded the maximum allowed memory usage of 40 MB


I request a help bacause i still face 40MB issue on MongoDb Server in CosmosDB despite the fact that i have upgraded the version to 4.0 (40 mb issue was fixed in 3.6).

I have a simple query that i am building using IMongoQerableInterface.

  protected Task<List<TEntity>> GetAllAsync(IMongoQueryable<TEntity> query)
    {
        return query.ToListAsync()
    }

above method from repository is later awaited in service. The query that is translated looks like below:

{aggregate([{ "$match" : { "Foo" : "Bar", "IsDeleted" : false } }])}

I have about 20k documents to query with "Bar" that i want to extract with a query that i am building:

var result = await GetAllAsync(DbQueryableCollection
            .Where(x=> x.Foo == "Bar" && x.IsDeleted == isDeleted))

When testing locally on my local machine it works fine. When published to Azure AppService, I recieve an error:

"Command aggregate failed: Query exceeded the maximum allowed memory usage of 40 MB. Please consider adding more filters to reduce the query response size.."

When I execute the same query but not using IMongoQuerable but IMongoCollection.FindAsync() with filter as an argument it works fine on AppService.

Below works fine.

var result =  await DbCollection.FindAsync(x => x.Model == model && x.IsDeleted == isDeleted);

I am using MongoDb.Driver for .Net v.2.12.3 (latest stable) I have created wildecard index on collection

Why I still see 40 MB issue on AppService when mongo server is upgraded to 4.0 and why it works locally?

Why query constructed with IMongoQueryable does not work in AppService but the one constructed with IMongoQuerable works ok and returns proper result?


Solution

  • Post an answer to end this question:

    Update the endpoint from documents.azure.com to mongo.cosmos.azure fix this issue.