Mongodb MongoError:WiredTigerIndex::insert:键太大,无法索引,失败23012,(尝试保存大字符串时失败)
我正试图将一个JSON字符串保存到mongoDB中,似乎字符串的长度太长了,我收到了以下错误消息Mongodb MongoError:WiredTigerIndex::insert:键太大,无法索引,失败23012,(尝试保存大字符串时失败),mongodb,mongoose,Mongodb,Mongoose,我正试图将一个JSON字符串保存到mongoDB中,似乎字符串的长度太长了,我收到了以下错误消息 MongoError: WiredTigerIndex::insert: key too large to index, failing 23012 我的模式相当简单 const metadataSchema = new Schema({ userId: { type: String, unique: false }, metadataJSON: { type: String, uni
MongoError: WiredTigerIndex::insert: key too large to index, failing 23012
我的模式相当简单
const metadataSchema = new Schema({
userId: { type: String, unique: false },
metadataJSON: { type: String, unique: false, failIndexKeyTooLong: false }
});
有没有关于如何插入这个大字符串的建议?提前感谢。可能重复的
failIndexKeyTooLong
参数是一个服务器配置选项(不是每个索引),不建议正确。此选项是为从2.6版之前的MongoDB部署迁移而创建的,该部署将插入文档,但在值长度大于1024字节时跳过索引。由于您的模式中的两个字段目前似乎都没有声明索引,我怀疑您以前可能已经定义了索引。尝试使用db.metadata.getIndexes()
(或调用集合的任何内容)通过mongo
shell检查索引。您可能需要在metadataJSON
上删除索引。
const saveMetadata = async (userId, customMetadata) => {
let metadata = METADATA({
userId: userId,
metadataJSON: JSON.stringify(customMetadata)
});
metadata.save(err => {
if (err)
console.log(
"ERROR - Metadata was not inserted and here is the reason : " + err
);
else console.log("All is good, metadata was inserted");
});
};