【问题标题】:Check through mongodb colletion for values in a field too large to index通过 mongodb 集合检查字段中的值太大而无法索引
【发布时间】:2016-09-03 09:47:42
【问题描述】:

我有一个 mongodb 集合,其中包含我正在尝试索引的字段。这是一个名为“title”的字符串字段。大约有 900 万个不同的条目,我只是想摆脱垃圾条目。

当我尝试使用以下方法对其进行索引时:

db.getCollection("review_metadata").createIndex({"title" : 1})

我收到此错误:

db.getCollection("review_metadata").createIndex({"title" : 1})

{
        "createdCollectionAutomatically" : false,
        "numIndexesBefore" : 2,
        "ok" : 0,
        "errmsg" : "Btree::insert: key too large to index, failing amazon_reviews.review_metadata.$title_1 1860 { : \"***Super Charger*** Ultra Slim 40W AC Power Adapter Cord for Samsung Notebook/UltraBook : NP300U1A, NP300U1A-A01US, NP305U1A, NP305U1A-A01US, NP305U1A...\" }",
        "code" : 17282
}

那么,有没有办法在标题字段中的所有值中搜索太大而无法索引的值?

【问题讨论】:

标签: mongodb indexing


【解决方案1】:

根据manaul,索引字段有 1024 个字节的限制。 当您要索引文本字段时 - text index 可能是一个很好的解决方案

db.review_metadata.createIndex(
   {
     title: "text",
     otherFieldThatCouldBeIndexedToo: "text"
   }
 )

【讨论】:

  • 我选择了这个解决方案,因为我只是在测试一些东西,需要对数据进行简单的 /^**** 搜索。谢谢。
猜你喜欢
  • 2011-09-16
  • 2015-03-03
  • 2018-10-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多