通过mongodb集合检查字段中的值是否太大而无法索引

时间:2016-05-08 20:01:56

标签: mongodb indexing

我有一个mongodb集合,其中包含一个我想要索引的字段。这是一个名为'title'的字符串字段。有大约900万个不同的条目,我只是想摆脱垃圾邮件。

当我尝试使用以下内容编制索引时:

z

我收到此错误:

  

db.getCollection(“review_metadata”)。createIndex({“title”:1})

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

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

1 个答案:

答案 0 :(得分:1)

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

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