错误:未启用文本搜索: - 在mongodb中

San*_*ngh 6 mongoose mongodb node.js mongoose-plugins

我收到以下错误: -

[Error: text search not enabled]
Run Code Online (Sandbox Code Playgroud)

我正在运行folliowing函数,它本质上是一个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 }));
        });
    });
}
Run Code Online (Sandbox Code Playgroud)

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

Sea*_*ory 16

在MongoDB 2.4中 - 启用实验文本搜索,使用

setParameter=textSearchEnabled=true

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

textSearchEnabled=true

编辑在MongoDB 2.6 +中默认启用.您只需要设置文本索引.


Phi*_*ipp 5

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

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

UPDATE

2.6mongoDB 版本开始,文本搜索功能具有生产质量并自动启用.