0
我一直在試圖保存一個MongoDB文件,並得到一個奇怪的錯誤,關鍵是太大,索引。我提供以下功能文件的例子,還有一個創建的錯誤:MongoDB失敗,因爲關鍵太大索引
功能:
{ uniquenumber: 'Valid Until Addition of Restrictions',
name: 'Valid Until Addition of Restrictions'
fieldofstudy: 'Valid Until Addition of Restrictions',
section: 'Valid Until Addition of Restrictions',
restrictions:
{ 'Must be assigned one of the following Student Attributes':
[ 'Non-Res. In-State',
'Non-Res. Out-of-State',
'DE Student Non-Res Out-of-St',
'Resident In-State',
'Res. Out-of-State' ],
'Must be enrolled in one of the following Levels': [ 'Graduate' ] },
times: [],
professors: [ 'Jo Blo' ] }
非功能性:
{
"uniquenumber": "Valid Until Addition of Restrictions",
"name": "Valid Until Addition of Restrictions",
"fieldofstudy": "Valid Until Addition of Restrictions",
"section": 'Valid Until Addition of Restrictions',
"restrictions": {
"May not be enrolled in one of the following Programs": ["MA [LA] Non-thesis option", "MS [AG] Non-thesis option", "MS [AR] Non-thesis option", "MS [BA] Non-thesis option", "MS [COFD] Non-thesis option", "MS [ED] Non-thesis option", "MS [EN] Non-thesis option", "MS [GE] Non-thesis option", "MS [LA] Non-thesis option", "MS [SC] Non-thesis option", "MS [VM] Non-thesis option", "MS NTO (Special Programs)", "MUP [AR] Non-thesis option"],
"Must be enrolled in one of the following Levels": ["Graduate"],
"May not be enrolled in one of the following Degrees": ["Master of Agribusiness", "Master of Agriculture", "Master of Architecture", "Master of Business Admin.", "Master of Computer Science", "Master of Education", "Master of Engineering", "Master of Land Econ & Real Est", "Master of Geoscience", "Master of Landscape Arch.", "Master of Public Administratn", "Master of Public Health", "Master of Public Svc & Admin"],
"May not be enrolled in one of the following Colleges": ["English Language Institute"],
"Must be assigned one of the following Student Attributes": ["Non-Res. In-State", "Non-Res. Out-of-State", "DE Student Non-Res Out-of-St", "Resident In-State", "Res. Out-of-State"],
"Must be enrolled in one of the following Classifications": ["G7-Graduate, Master's Level", "G8-Graduate, Doctoral Level", "G9-Graduate, Mas/Doc Admitted"]
},
"times": [],
"professors": []
}
直到創造的restrictions
對象,刮刀正常工作,所以我相信錯誤可以縮小到那裏。但是,我不清楚哪些鍵「太大」而無法被索引。如果我的猜測是正確的,爲什麼Mongo把它算作關鍵,我該如何彌補這種情況?
編輯:於db.Section.getIndexes();
響應如下所示:
[
{
"v" : 2,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "database.Section"
},
{
"v" : 2,
"unique" : true,
"key" : {
"uniquenumber" : 1
},
"name" : "uniquenumber_1",
"ns" : "database.Section",
"background" : true
},
{
"v" : 2,
"key" : {
"name" : 1
},
"name" : "name_1",
"ns" : "database.Section",
"background" : true
},
{
"v" : 2,
"key" : {
"fieldofstudy" : 1
},
"name" : "fieldofstudy_1",
"ns" : "database.Section",
"background" : true
},
{
"v" : 2,
"key" : {
"course" : 1
},
"name" : "course_1",
"ns" : "database.Section",
"background" : true
},
{
"v" : 2,
"key" : {
"section" : 1
},
"name" : "section_1",
"ns" : "database.Section",
"background" : true
},
{
"v" : 2,
"key" : {
"professors" : 1
},
"name" : "professors_1",
"ns" : "database.Section",
"background" : true
},
{
"v" : 2,
"key" : {
"times" : 1
},
"name" : "times_1",
"ns" : "database.Section",
"background" : true
},
{
"v" : 2,
"key" : {
"restrictions" : 1
},
"name" : "restrictions_1",
"ns" : "database.Section",
"background" : true
}
]
喜Quontas;你能告訴我們你在這個系列上有什麼索引嗎? –
作爲參考,索引條目的總大小必須小於1024字節(https://docs.mongodb.com/manual/reference/limits/#Index-Key-Limit)。該錯誤表示索引存在於此集合上,以致非功能文檔中的值超出此限制。如果不知道現有的索引,我們不能說是什麼原因導致了失敗,但我猜測你已經爲「限制」字段建立了索引。 –
原始帖子中顯示了對'db.Section.getIndexes();'的響應。 – Quontas