2016-05-08 68 views
1

我有一个我试图建立索引的字段的mongodb集合。这是一个标题为“标题”的字符串字段。有大约900万不同的条目,我只是试图摆脱垃圾。通过mongodb收集检查字段值太大,以索引

当我试图用其编入索引:

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 
} 

那么,有没有一种方法,通过所有值在标题栏来搜索对于索引太大的值?

+2

的可能重复:http://stackoverflow.com/questions/29577713/string-field-value-length-in-mongodb –

+1

同意,只需使用1012的最小长度来查找违规文档。 'db.test.find({title:/ ^。{1012,} $ /})'。 – JohnnyHK

回答

1

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

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

我使用这个解决方案,因为我只是测试一些东西,需要对数据进行简单的/^****搜索。谢谢。 – Zeratas