mongodb - MongoDB 模式验证在更新时失败,但没有一次插入
问题描述
我有一个带有模式验证的 Mongodb 集合。我执行db.correspondence.validate({full:true})
并收到"nInvalidDocuments" : NumberLong(0)
我可以插入文档,但更新失败。
MongoDB Enterprise > db.correspondence.find({"correspondenceIdentifier": "ca4697e2-a40c-11ea-a632-0a0a6b0e0000"}).count()
8
MongoDB Enterprise > db.correspondence.insert({"correspondenceIdentifier": "ca4697e2-a40c-11ea-a632-0a0a6b0e0000",mdmContractIdentifier:'3334444444444444','name':'Vat'});
WriteResult({ "nInserted" : 1 })
MongoDB Enterprise > db.correspondence.find({"correspondenceIdentifier": "ca4697e2-a40c-11ea-a632-0a0a6b0e0000"}).count()
9
MongoDB Enterprise > db.correspondence.find({mdmContractIdentifier:'3334444444444444'}).count()
2
MongoDB Enterprise > db.correspondence.updateOne({"correspondenceIdentifier": "ca4697e2-a40c-11ea-a632-0a0a6b0e0000"},{$set:{mdmContractIdentifier:'3334444444444444'}});
2020-08-05T20:50:28.164-0400 E QUERY [thread1] **WriteError: Document failed validation** :
WriteError({
"index" : 0,
"code" : 121,
"errmsg" : "Document failed validation",
"op" : {
"q" : {
"correspondenceIdentifier" : "ca4697e2-a40c-11ea-a632-0a0a6b0e0000"
},
"u" : {
"$set" : {
"mdmContractIdentifier" : "3334444444444444"
}
},
"multi" : false,
"upsert" : false
}
})`
WriteError@src/mongo/shell/bulk_api.js:466:48
Bulk/mergeBatchResults@src/mongo/shell/bulk_api.js:846:49
Bulk/executeBatch@src/mongo/shell/bulk_api.js:910:13
Bulk/this.execute@src/mongo/shell/bulk_api.js:1154:21
DBCollection.prototype.updateOne@src/mongo/shell/crud_api.js:572:17
@(shell):1:1
解决方案
推荐阅读
- docker - 可以将 docker 注册表从一台机器复制到另一台机器吗?
- javascript - fileReader.onload 不会第二次运行,即使选择了不同的文件
- alexa-skills-kit - 上传清单文件失败
- java - 如果元素在 java 中不存在,则添加该元素
- c++ - 在 gtest 中使用 opencv 对象:成功后测试永远不会结束
- python - 在python中使用itertools进行组合
- javascript - touchstart 事件的问题
- javascript - 当作为道具传递给另一个组件时,离子图标不显示
- php - 试图循环遍历数组并将值传递给 php cURL 请求
- drupal - 将 Drupal 8.9.13 迁移到 9.0.1 的问题