Node.js MongoDB失败,因为键太大,无法索引
我一直在尝试保存MongoDB文档,但遇到了一个奇怪的错误,即密钥太大,无法索引。我在下面提供了一个功能文档的示例,以及一个创建错误的示例: 功能性:Node.js MongoDB失败,因为键太大,无法索引,node.js,mongodb,mongoose,wiredtiger,Node.js,Mongodb,Mongoose,Wiredtiger,我一直在尝试保存MongoDB文档,但遇到了一个奇怪的错误,即密钥太大,无法索引。我在下面提供了一个功能文档的示例,以及一个创建错误的示例: 功能性: { uniquenumber: 'Valid Until Addition of Restrictions', name: 'Valid Until Addition of Restrictions' fieldofstudy: 'Valid Until Addition of Restrictions', section: 'Val
{ 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": []
}
非功能性:
{ 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": []
}
在创建限制
对象之前,scraper按预期工作,因此我相信错误可以缩小到这一点。然而,我不清楚任何键在哪里“太大”而无法索引。如果我的猜测是正确的,为什么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
}
]
你有一个关于限制
的索引,根据你的数据,这个索引是完全无用的,而且会非常大,因为它是一个子文档
您可能希望从集合中删除该索引:
db.Section.dropIndex({restrictions: 1});
嗨,昆塔斯;你能告诉我们你在这个集合上有什么索引吗?作为参考,索引项的总大小必须小于1024字节()。错误指示此集合上存在索引,因此非功能文档中的值超出了该限制。在不知道现有索引的情况下,我们无法说出导致失败的原因,但我猜您已经为“restrictions”字段编制了索引代码>显示在原始帖子中。你有一个关于限制
的索引,根据你的数据,它是完全无用的,而且会非常大。您可能希望从集合中删除该索引。当然,不要在该字段上创建索引。