【问题标题】:How to text index in mongodb using nodejs如何使用nodejs在mongodb中进行文本索引
【发布时间】:2015-02-20 11:29:27
【问题描述】:

我正在尝试使用 nodejs 在 mongodb 中为文本搜索实现创建文本索引。

例如:

db.collection("test").ensureIndex(
                       { 
                          name: 'text', 
                          description: 'text' 
                       }, 
                       { 
                          weights: { name: 10, description: 20 }, 
                           name: 'test' 
                      }, function(err, data){

                 // here err is null, and data is "test"

 });

之后我试图获取这个名为“test”的索引的信息,它给了我类似的数据

 { v: 1,
   key: { _fts: 'text', _ftsx: 1 },
   ns: '53b3e49b31afd3d3354886b7_rajeshdemo.test',
   name: 'test',
   weights: { description: 1, name: 1 },
   default_language: 'english',
   language_override: 'language',
   textIndexVersion: 1 
}

它没有获取重量信息。

如何使用 nodejs 在 mongodb(2.6 版)中创建文本搜索索引?

【问题讨论】:

  • 如果已存在与提供的键规范 ({name:'text',description:'text') 匹配的索引,则 ensureIndex 将不会使用新选项重新创建索引。您是否尝试过删除索引然后重新确保?
  • 是的,我在调用 ensureIndex 之前删除了文本索引。

标签: node.js mongodb


【解决方案1】:

我找到了解决办法。

实际上我使用的是 nodejs mongodb 驱动程序 1.4.5。将版本更新到1.4.9后,就可以正常使用了。

【讨论】:

    猜你喜欢
    • 2019-06-03
    • 2020-09-14
    • 2012-06-24
    • 2016-07-08
    • 1970-01-01
    • 2014-11-19
    • 1970-01-01
    • 2021-03-22
    • 2013-04-06
    相关资源
    最近更新 更多