6

I get the following error :-

[Error: text search not enabled]

I am running the folliowing function which is essentially a mongoose-mongodb operation.

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 }));
        });
    });
}

I am trying to implement the mongoose-text-search plugin

Sangram Singh
  • 7,161
  • 15
  • 50
  • 79
  • 1
    possible duplicate of [Installing plugins for mongoose - getting error](http://stackoverflow.com/questions/16513040/installing-plugins-for-mongoose-getting-error) – WiredPrairie Nov 10 '13 at 21:28
  • If you search for that error string, it's quite simple to find the most likely reason. – WiredPrairie Nov 10 '13 at 21:29

3 Answers3

16

In MongoDB 2.4 - to enable the experimental text search, use

setParameter=textSearchEnabled=true

The following line didn't work for me in the mongodb.conf file.

textSearchEnabled=true

EDIT In MongoDB 2.6 + it is enabled by default. You just need to set up your text indexes.

Sean McClory
  • 4,195
  • 3
  • 32
  • 35
  • I upgraded my MongoDB to 2.6 and I still got "MongoError: text search not enabled". Is there any way to check whether textSearchEnabled is true or false? – Daniel Qiu Jun 21 '14 at 00:44
  • [textSearchEnabled is deprecated since 2.6](http://docs.mongodb.org/manual/reference/parameters/#param.textSearchEnabled). Perhaps that is why it is showing up as not enabled. Not sure how you check. TextSearch works differently (as of 2.6), with the `$text` operator returning multiple docs, rather than `text` returning just the one docs (of docs) in 2.4. Also, check your `version()` in the mongoshell. – Sean McClory Jun 21 '14 at 10:55
5

MongoDB Text search is still an experimental feature. That's why it is disabled by default and must be enabled manually. You can do so by either starting mongod with the command line parameter --setParameter textSearchEnabled=true or adding the line textSearchEnabled=true to the file mongodb.conf.

Please note that as an experimental feature, text search should not be used in a production environment yet.

UPDATE

As of version 2.6 of mongoDB text search feature has production-quality and is enabled automatically.

Philipp
  • 67,764
  • 9
  • 118
  • 153
0

You have to specify this startup parameter (mentioned in above answers) when you start mongo. So if you start manually, then use:

mongod --setParameter textSearchEnabled=true 

Otherwise, if mongo is deamonized, put it into deamon script. Something like this:

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

Then you create text index and check it's existence:

db.mycoll.createIndex( { someFieldName: "text" } );
db.mycoll.getIndexes()
Mitja Gustin
  • 1,723
  • 13
  • 17