错误:未启用文本search: – 在mongodb中

我得到以下错误:

[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文本search插件

MongoDB文本search仍然是一个实验性的function。 这就是为什么它被默认禁用, 必须手动启用 。 您可以通过使用命令行参数--setParameter textSearchEnabled=true来启动mongod,或者将--setParameter textSearchEnabled=true--setParameter textSearchEnabled=true添加到文件mongodb.conf中。

请注意,作为实验性function,文本search不应该在生产环境中使用。

UPDATE

从mongoDB版本2.6 ,文本searchfunction具有生产质量并自动启用。

在MongoDB 2.4中 – 启用实验文本search,使用

setParameter=textSearchEnabled=true

下面一行在我的mongodb.conf文件中不起作用。

textSearchEnabled=true

编辑在MongoDB 2.6 +它是默认启用。 你只需要设置你的文字索引。