is it possible to perform a case insensitive search on DocumnetDb?
Let\'s say I have a record with \'name\' key and value as \"Timbaktu\"
This will work:
There are two ways to do this. 1. use the built-in LOWER/UPPER function, for example,
select * from json j where LOWER(j.name) = 'timbaktu'
This will require a scan though. Another more efficient way is to store a "canonicalized" form e.g. lowercase and use that for querying. For example, the JSON would be
{ name: "Timbaktu", nameLowerCase: "timbaktu" }
Then use it for querying like:
select * from json j WHERE j.nameLowerCase = "timbaktu"
Hope this helps.
Perhaps this is an ancient case, I just want to provide a workaround.
You could use UDF in azure cosmos db.
udf:
function userDefinedFunction(str){
return str .toLowerCase();
}
And use below sql to query results:
SELECT c.firstName FROM c where udf.lowerConvert(c.firstName) = udf.lowerConvert('John')
Cosmos recently added a case-insensitive option for string functions:
You now have an option to make these string comparisons case-insensitive: Contains, EndsWith, StringEquals, and StartsWith. and Significant performance improvements have been realized for these string system functions. Each of these four string system functions now benefit from an index and will therefore have much lower latency and request unit (RU) consumption.
Announcement