I have a .Net application who interact with a mongoDb database on CosmosDb.
I have a find
request who looks like this :
public async Task<int?> GetCurrentZonierVersionNumberAsync(string productCode, string risqueType)
{
if (string.IsNullOrEmpty(productCode) || string.IsNullOrEmpty(risqueType))
{
throw new ArgumentNullException();
}
var filter = Builders<Zonier>.Filter.And(
Builders<Zonier>.Filter.Eq(x => x.ProductCode, productCode),
Builders<Zonier>.Filter.Eq(c => c.RisqueType, risqueType));
Zonier result = null;
try
{
var query = _collection.Find(filter).SortByDescending(x => x.Version).Limit(1).FirstOrDefaultAsync();
await _retryPolicy.ExecuteAsync(async () =>
{
result = await query;
});
}
catch (TimeoutException ex)
{
throw new DataBaseReadingException(ex.Message, ExceptionCodeConstants.DataBaseReadingExceptionCode);
}
return result?.Version;
}
Unfortunately I get the following error message on azure :
Unhandled Exception: MongoDB.Driver.MongoCommandException: Command find failed: The provided cross partition query can not be directly served by the gateway. This is a first chance (internal) exception that all newer clients will know how to handle gracefully. This exception is traced, but unless you see it bubble up as an exception (which only happens on older SDK clients), then you can safely ignore this message.
I dont understand what is happening. Can someone please explain me the error message. I have the 2.4.4 version of the mongo driver. I'm aware I should update it, but I'm scared it will hide the issue without resolving it. Should I add this type of exception inside the retry policy of Polly ?
_id
field – Xavier W.