我在unique indexes
EmbenddedDocuments
时遇到了一些问题
我有以下架构:
{
"_id": ObjectId("58da1dd3d1f0e80cac0002e2"),
"slug": "about-us",
"languages": [{
"title": "About us",
"content": "Here is something written about us",
"language": DBRef("languages", ObjectId("58d29616d1f0e82574007d12"), "XXX"),
"keywords": [],
"description": "Here you can find all information about our company"
},
{
"title": "About us",
"content": "Here is something written about us",
"language": DBRef("languages", ObjectId("58d29616d1f0e82574007d13"), "XXX"),
"keywords": [],
"description": "Here you can find all information about our company"
},
{
"title": "About us",
"content": "Here is something written about us",
"language": DBRef("languages", ObjectId("58d29616d1f0e82574007d13"), "XXX"),
"keywords": [],
"description": "Here you can find all information about our company"
},
{
"title": "About us",
"content": "Here is something written about us",
"language": DBRef("languages", ObjectId("58d29616d1f0e82574007d13"), "XXX"),
"keywords": [],
"description": "Here you can find all information about our company"
}
]
}
并创建了以下indexes
:
/* 1 */
{
"key": {
"_id": NumberInt("1")
},
"name": "_id_",
"ns": "XXX.pages",
"v": NumberInt("2")
},
/* 2 */
{
"key": {
"slug": NumberInt("1")
},
"name": "slug_1",
"ns": "XXX.pages",
"sparse": false,
"unique": true,
"v": NumberInt("2")
},
/* 3 */
{
"key": {
"languages.language.$id": 1
},
"name": "languages.language.$id_1",
"ns": "XXX.pages",
"sparse": true,
"unique": true,
"v": NumberInt("2")
}
正如您在架构中看到的,我可以在页面上创建新的EmbenddedDocuments
。但它应该给我一个错误?
我使用此命令插入EmbenddedDocument
db.pages.update({
"_id": ObjectId("58da1dd3d1f0e80cac0002e2")
}, {
"$pushAll": {
"languages": [{
"title": "About us",
"content": "Here is something written about us",
"language": {
"$ref": "languages",
"$id": ObjectId("58d29616d1f0e82574007d13"),
"$db": "XXX"
},
"keywords": [],
"description": "Here you can find all information about our company"
}]
}
});