【问题标题】:Unique Sparse Index on cosmosdb not workingcosmosdb 上的唯一稀疏索引不起作用
【发布时间】:2019-04-01 16:03:36
【问题描述】:

我的文件是:

{
 "firstName" : "My first name",
 "lastName": "My lastName",
}

我已使用唯一稀疏索引为字段fristNamelastName 编制索引。这意味着我的数据库中将始终拥有唯一的 firstNamelastName

但对于字段firstNamelastName,它可以有空值(即,将其插入数据库时​​缺少字段)。

在 MongoDB v3.4 中运行良好。但是当我尝试在 cosmosdb 中使用相同的代码插入时,我得到了错误

multiple write errors: [{write errors: [{E11000 duplicate key error collection: user Failed _id or unique key constraint}]}, {<nil>}]

cosmosdb 是否支持唯一稀疏索引?

我发现这个link 说它不支持uniue sparse index

默认情况下支持link 表示sparse index

【问题讨论】:

    标签: azure-cosmosdb azure-cosmosdb-mongoapi


    【解决方案1】:

    唯一稀疏索引和基于稀疏文档属性的defining a collection unique key 之间存在差异。因此,您的帖子中关于它的部分不受支持:

    I found this link which say it do not support uniue sparse index.

    真的是说不支持使用稀疏文档属性作为分区键:

    不支持稀疏唯一键。如果缺少某些唯一路径值,它们将被视为空值,它们参与唯一性约束。因此,只有一个值为空的项目才能满足此约束。

    请看下面的 Stack Overflow post

    【讨论】:

      猜你喜欢
      • 2013-06-12
      • 1970-01-01
      • 1970-01-01
      • 2015-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-29
      • 2018-06-12
      相关资源
      最近更新 更多