Lets say I have these documents in my CosmosDB. (DocumentDB API, .NET SDK)
{
// partition key of the collection
"userId" : "0000-0000-0000-0000",
"emailAddresses": [
"[email protected]", "[email protected]"
]
// some more fields
}
I now need to find out if I have a document for a given email address. However, I need the query to be case insensitive.
There are ways to search case insensitive on a field (they do a full scan however):
How to do a Case Insensitive search on Azure DocumentDb?
select * from json j where LOWER(j.name) = 'timbaktu'
e => e.Id.ToLower() == key.ToLower()
These do not work for arrays. Is there an alternative way? A user defined function looks like it could help.
I am mainly looking for a temporary low-effort solution to support the scenario (I have multiple collections like this). I probably need to switch to a data structure like this at some point:
{
"userId" : "0000-0000-0000-0000",
// Option A
"emailAddresses": [
{
"displayName": "[email protected]",
"normalizedName" : "[email protected]"
},
{
"displayName": "[email protected]",
"normalizedName" : "[email protected]"
}
],
// Option B
"emailAddressesNormalized": {
"[email protected]", "[email protected]"
}
}
Unfortunately, my production database already contains documents that would need to be updated to support the new structure. My production collections contain only 100s of these items, so I am even tempted to just get all items and do the comparison in memory on the client.