【问题标题】:Error: text search not enabled:- in mongodb错误:未启用文本搜索:- 在 mongodb
【发布时间】:2013-11-22 13:48:58
【问题描述】:

我收到以下错误:-

[Error: text search not enabled]

我正在运行以下函数,它本质上是一个 mongoose-mongodb 操作。

var textSearch = require('mongoose-text-search');

exports.dbTextSearch = function () {
    console.log('dbTextSearch');
    var gameSchema = mongoose.Schema({
        name: String
      , tags: [String]
      , likes: Number
      , created: Date
    });

    gameSchema.plugin(textSearch);

    gameSchema.index({ tags: 'text' });

    var Game = mongoose.model('Game', gameSchema);

    Game.create({ name: 'Super Mario 64', tags: ['nintendo', 'mario', '3d'] }, function (err) {
    Game.textSearch('3d', function (err, output) {
        if (err) return console.log(err); // this outputs the error.
        var inspect = require('util').inspect;
      console.log(inspect(output, { depth: null }));
        });
    });
}

我正在尝试实现mongoose-text-search 插件

【问题讨论】:

标签: node.js mongodb mongoose mongoose-plugins


【解决方案1】:

MongoDB 文本搜索仍然是一个实验性功能。这就是默认情况下禁用它和must be enabled manually 的原因。您可以通过使用命令行参数 --setParameter textSearchEnabled=true 启动 mongod 或将行 textSearchEnabled=true 添加到文件 mongodb.conf 来实现。

请注意,作为一项实验性功能,文本搜索目前不应在生产环境中使用。

更新

截至2.6 版本的 mongoDB 文本搜索功能具有生产质量并自动启用。

【讨论】:

    【解决方案2】:

    在 MongoDB 2.4 - 要启用实验性文本搜索,请使用

    setParameter=textSearchEnabled=true

    以下行在 mongodb.conf 文件中对我不起作用。

    textSearchEnabled=true

    EDIT 在 MongoDB 2.6 + 中默认启用。你只需要设置你的文本索引。

    【讨论】:

    • 我将 MongoDB 升级到 2.6,但仍然出现“MongoError:未启用文本搜索”。有什么方法可以检查 textSearchEnabled 是真还是假?
    • textSearchEnabled is deprecated since 2.6。也许这就是它显示为未启用的原因。不知道你是怎么检查的。 TextSearch 的工作方式有所不同(从 2.6 开始),$text 运算符返回多个文档,而不是 text 在 2.4 中仅返回一个文档(文档)。另外,请在 mongoshell 中检查您的 version()
    【解决方案3】:

    你必须在启动 mongo 时指定这个启动参数(在上面的答案中提到)。因此,如果您手动启动,则使用:

    mongod --setParameter textSearchEnabled=true 
    

    否则,如果 mongo 被 deamonized,则将其放入 deamon 脚本中。像这样的:

    start()
    {
      echo -n $"Starting mongod: "
      daemon --user "$MONGO_USER" $NUMACTL $mongod --setParameter textSearchEnabled=true $OPTIONS
    

    然后你创建文本索引并检查它是否存在:

    db.mycoll.createIndex( { someFieldName: "text" } );
    db.mycoll.getIndexes()
    

    【讨论】:

      猜你喜欢
      • 2016-05-28
      • 2012-03-26
      • 1970-01-01
      • 2014-01-11
      • 2018-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多