Mongodb 数组型索引报错:WiredTigerIndex::insert: key too large to index, failing

mongodb支持很多种索引,参看官网:https://docs.mongodb.com/manual/indexes/#index-use

创建一个简单索引: db.collection.createIndex({‘name’:1})
这种方式的索引,默认是比较小的,如果值过长就会报错WiredTigerIndex::insert: key too large to index, failing
可以该种hasded的方式 db.collection.createIndex({‘name’:’hashed’}),
如果name是数组格式,而不是字符串,就不能用hashed的索引格式了,这样,我们需要通过另外的方法来解决

https://docs.mongodb.com/manual/reference/parameters/#param.failIndexKeyTooLong

通过设置参数 failIndexKeyTooLong 为false来解决,文档里面有具体的方法,

我的mongodb的启动方式为:

/usr/bin/mongod -f /etc/mongod.conf

我在 /etc/mongod.conf 配置文件中添加下面的配置

setParameter:
  failIndexKeyTooLong: false

关于mongodb的config的详细可以参看地址:

https://docs.mongodb.com/manual/reference/configuration-options/

通过上面的方式,重启mongodb,解决了我的问题,不报错了

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注