0

我定义了一个像

{

    'info' : {
        'type' : 'dict',
        'unique' : True,
        'schema' : {
            'propertyA' : {'type':'string'},
            'propertyB' : {'type':'string'},
            'propertyC' : {'type':'string'}

        }
    },

    'others' : {'type':'string'}
}

然后,我将以下文档发布了两次,第一次返回 OK,第二次返回“非唯一错误”。

[
  {
    "info" : {
      "propertyA" : "a",
      "propertyB" : "b",
      "propertyC" : "c"
    },
    "others" : "other things"
  }
]

但是当我按如下方式发布文档列表时:

[
  {
    "info" : {
      "propertyA" : "a",
      "propertyB" : "b",
      "propertyC" : "c"
    },
    "others" : "other things"
  },
  {
    "info" : {
      "propertyA" : "a",
      "propertyB" : "b",
      "propertyC" : "c"
    },
    "others" : "other things"
  }
]

两个文档都插入到数据库中。

为什么他们有不同的结果?

4

1 回答 1

0

发生这种情况是因为在第二种情况下,两个文档都将通过一个环回数据库存储,从而利用 MongoDB 批量插入功能。因此,当根据数据库验证第二个文档时,还没有找到重复的文档。

在第一个场景中,您正在执行两个单独的保存操作,因此第二个将匹配副本。

于 2014-05-16T14:04:43.347 回答