首页 \ 问答 \ 对CosmosDB / DocumentDB的数组进行大小写不敏感的搜索(Case insensitive search in arrays for CosmosDB / DocumentDB)

对CosmosDB / DocumentDB的数组进行大小写不敏感的搜索(Case insensitive search in arrays for CosmosDB / DocumentDB)

比方说,我有这些文件在我的CosmosDB。 (DocumentDB API,.NET SDK)

{
    // partition key of the collection
    "userId" : "0000-0000-0000-0000",
    "emailAddresses": [
        "someaddress@somedomain.com", "Another.Address@someotherdomain.com"
    ]
    // some more fields
}

我现在需要知道是否有给定电子邮件地址的文档。 但是,我需要查询不区分大小写。

有一些方法可以在字段中搜索不区分大小写的字段(但它们会执行全面扫描):

如何在Azure DocumentDb上执行不区分大小写的搜索?

select * from json j where LOWER(j.name) = 'timbaktu'
e => e.Id.ToLower() == key.ToLower()

这些不适用于数组。 有其他方法吗? 用户定义的函数看起来可能有所帮助。

我主要是在寻找一种暂时的低效解决方案来支持这种情况(我有这样的多个集合)。 我可能需要在某个时候切换到这样的数据结构:

{
    "userId" : "0000-0000-0000-0000",
    // Option A
    "emailAddresses": [
        {
            "displayName": "someaddress@somedomain.com",
            "normalizedName" : "someaddress@somedomain.com"
        },
        {
            "displayName": "Another.Address@someotherdomain.com",
            "normalizedName" : "another.address@someotherdomain.com"
        }
    ],
    // Option B
    "emailAddressesNormalized": {
        "someaddress@somedomain.com", "another.address@someotherdomain.com"
    }
}

不幸的是,我的生产数据库已经包含需要更新以支持新结构的文档。 我的生产集合中只包含100个这样的项目,所以我甚至想要获取所有项目并在客户端的内存中进行比较。


Lets say I have these documents in my CosmosDB. (DocumentDB API, .NET SDK)

{
    // partition key of the collection
    "userId" : "0000-0000-0000-0000",
    "emailAddresses": [
        "someaddress@somedomain.com", "Another.Address@someotherdomain.com"
    ]
    // 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": "someaddress@somedomain.com",
            "normalizedName" : "someaddress@somedomain.com"
        },
        {
            "displayName": "Another.Address@someotherdomain.com",
            "normalizedName" : "another.address@someotherdomain.com"
        }
    ],
    // Option B
    "emailAddressesNormalized": {
        "someaddress@somedomain.com", "another.address@someotherdomain.com"
    }
}

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.


原文:https://stackoverflow.com/questions/47596474
更新时间:2022-04-14 09:04

最满意答案

关于这个wiki的testthat包有很好的文档: https//github.com/hadley/devtools/wiki/Testing

简而言之,您可以在每个test_that嵌入多个expect_that语句。

在页面的末尾,在“测试文件和目录”部分中,有关于三个不同报告者的信息(停止,最小和摘要)。

我发现这非常强大。 即使test_that发现错误,它也只是报告错误并继续进行其余的测试。

PS。 我的经验是将测试结果打印到控制台。 我在R环境中运行我的测试,而不是OS命令行。


There is a very good documentation about the testthat package at this wiki: https://github.com/hadley/devtools/wiki/Testing

In a nutshell, you can embed multiple expect_that statements in each test_that.

Towards the end of the page, in the section 'Testing files and directories' there is information about the three different reporters (stop, minimal and summary).

I have found this to be quite robust. Even if test_that finds an error, it simply reports the error and carries on with the remainder of the tests.

PS. My experience is that the test results are printed to the console. I run my testing from within the R environment, not the OS command line.

相关问答

更多
  • find
  • 对于每个测试gitlab-ci清理构建文件夹,因此构建阶段的输出文件在部署阶段不可用。 您还需要在部署阶段重建您的项目。 这些“阶段”仅用于订购测试,即避免在构建测试失败时尝试执行部署测试。 编辑:自Gitlab 8.6以来,可以使用依赖项功能 For each test gitlab-ci clean the build folder, therefore the output files of the build stage are not available in the deploy stage. ...
  • 目前,您没有指定终止条件: lexer([H|TokenList],Output,[Output|X2]):- lexer_test(H,Output),lexer(TokenList,Output,X2). Lexer一直在调用自己(递归),但是你没有指定其他子句,因此Prolog最终会进入无限循环。 您正在寻找的条件是: lexer([],_,[]). 作为停止条件。 这表明令牌列表变空的情况。 开始学习prolog(imho)的好地方是: http : //www.learnprologno ...
  • 我建议在输出中为unix时间戳添加另一个字段。 在gnu find的-printf格式字符串中,这表示为%T@ 。 例如,要排序你可以做的所有事情: find / -type f -printf "%T@ Date: %TY-%Tm-%Td - Time: %TT - File: %f\n" \ | LC_ALL=C sort -n -k1,1 \ | cut -d' ' -f2- sort -n -k1,1在stdin中对第一列(仅包含第一列)中的行进行数字排序。 LC_ALL=C环境变 ...
  • 你不能提供Windows本机程序Cygwin路径,他们不明白。 但是,您可以将包装器脚本放在与ffmpeg.exe相同的文件夹中,并将其命名为ffmpeg 。 喜欢这个 #!/bin/sh for each do foo=$(cygpath -w -- "$each") bar+=("$foo") done ffmpeg.exe "${bar[@]}" 然后你就离开了 $ ffmpeg.exe -i 1_Les_Nuits.mp3 /tmp/outfile.m4a /tmp/outfile.m4a ...
  • 构建gmp(gcc的先决条件)时会产生此错误。 这是4.8.3 Ref:gmp bug中gmp中的一个已知错误 。 如果运行contrib / download_prerequisites,默认情况下会得到gmp 4.8.3。 解决方法是编辑gmp-4.8.3 / configure.in和gmp-4.8.3 / configure和change M4=m4-not-required 对于 M4=m4 This error is generated whilst building gmp (a pre-re ...
  • 你可能想要执行一个shell。 就像是: find . -type f -name \*.mp4 -exec sh -c 'ffprobe "$0" 2>&1 | grep -q 1920x1080 && echo "$0"' {} \; You probably want to exec a shell. Something like: find . -type f -name \*.mp4 -exec sh -c 'ffprobe "$0" 2>&1 | grep -q 1920x10 ...
  • 关于这个wiki的testthat包有很好的文档: https : //github.com/hadley/devtools/wiki/Testing 简而言之,您可以在每个test_that嵌入多个expect_that语句。 在页面的末尾,在“测试文件和目录”部分中,有关于三个不同报告者的信息(停止,最小和摘要)。 我发现这非常强大。 即使test_that发现错误,它也只是报告错误并继续进行其余的测试。 PS。 我的经验是将测试结果打印到控制台。 我在R环境中运行我的测试,而不是OS命令行。 Ther ...
  • 它可能在~/Library/Developer/Xcode/DerivedData/某处。 It's probably in ~/Library/Developer/Xcode/DerivedData/ somewhere.
  • 从你的评论中看出,你用gcc而不是g++ 。 不要把它当成错误,因为编译很好! 出现的是链接器错误。 实际上, gcc会告诉ld链接C标准库而不是C ++标准库。 要解决,要么直接使用g++ ,要么传递-lstdc++ 。 As turns out from your comment, you compiled with gcc rather than g++. Do not take it as an error, as the compilation went fine! What's showing ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)