Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: text search not enabled:- in mongodb

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

like image 240
Sangram Singh Avatar asked Nov 10 '13 20:11

Sangram Singh


People also ask

How do I search for text in MongoDB?

Use the $text query operator to perform text searches on a collection with a text index. $text will tokenize the search string using whitespace and most punctuation as delimiters, and perform a logical OR of all such tokens in the search string.

How does MongoDB text search work?

MongoDB text search uses the Snowball stemming library to reduce words to an expected root form (or stem) based on common language rules. Algorithmic stemming provides a quick reduction, but languages have exceptions (such as irregular or contradicting verb conjugation patterns) that can affect accuracy.

Is MongoDB full text search?

MongoDB offers a full-text search solution, MongoDB Atlas Search, for data hosted on MongoDB Atlas.

How do I create a search in MongoDB?

In MongoDB, we can perform text search using text index and $text operator. Text index: MongoDB proved text indexes that are used to find the specified text from the string content. Text indexes should be either a string or an array of string elements.


2 Answers

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.

like image 138
Sean McClory Avatar answered Oct 06 '22 08:10

Sean McClory


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.

like image 30
Philipp Avatar answered Oct 06 '22 07:10

Philipp