MongoDB 2.4 新的文本索引功能

标签 mongodb

所以我有一个奇怪配置的数据库导入到 MongoDB 中,如下所示:

"_id" : ObjectId("51191d45890311d9b2a0865d"),
"field1" : "randomtextstuff",
"field2" : "randomtextstuff",
"field3" : "randomtextstuff",
"field4" : "randomtextstuff",
"field5" : "randomtextstuff"

某些文档有 100 个字段,而其他文档则没有。

所以我想测试新的文本搜索,所以我尝试了以下索引:

db.profile_specialties.ensureIndex({"field1":"text",
"field2":"text",
"field3":"text",
"field4":"text",
"field5":"text",
"field6":"text",
... All the way to 100
"field96":"text",
"field97":"text",
"field98":"text",
"field99":"text",
"field100":"text"})

返回的错误消息是:

{
        "err" : "ns name too long, max size is 128",
        "code" : 10080,
        "n" : 0,
        "connectionId" : 1,
        "ok" : 1
}

还有人遇到过这个问题吗?

最佳答案

通过 MongoDB 2.4 文本搜索,您可以使用新的 wildcard specifier ($**)用字符串内容索引所有字段:

db.profile_specialties.ensureIndex("$**":"text"})

不过,您应该考虑到跨所有字段的文本索引将会非常大。

关于MongoDB 2.4 新的文本索引功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15532739/

相关文章:

不使用 db.eval() 的 django 中用于 mongodb 的 Python ORM

mongodb - 如何从集合中删除除 MongoDB 中的文档之外的所有文档

mongodb - $concat mongodb 中的两个字段

node.js - 如何使用nodeJS MongoClient按顺序打印数据库名称及其集合名称?

mongodb - $group 需要一个 _id 数组,但 $out 不会处理它

javascript - NodeJS/MongoDB 唯一值检查

mongodb - mongo 更新($set)在单个文档上是原子的

mongodb - 部署/auth-mongo-depl : container auth-mongo is waiting to start: mongo can't be pulled

node.js - 类型错误 : Converting circular structure to JSON when changed to NodeJS Async Await

mongodb - Ember、Ember 数据和 MongoDB 的 _id