MongoError:WiredTigerIndex :: insert:键太大而无法索引,失败23012,(尝试保存大字符串时失败)

时间:2019-09-01 21:13:06

标签: 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, unique: false, failIndexKeyTooLong: false }
});
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");
  });
};

关于如何插入此大字符串的任何建议?预先感谢。

0 个答案:

没有答案