cathy.sasaki
cathy.sasaki

Reputation: 4025

Installing plugins for mongoose - getting error

I'm trying to add in my first plugin - mongoose-text-search.

https://npmjs.org/package/mongoose-text-search

I'm getting the error: How to Error: text search not enabled that I can't figure out.

I have my schema in seperate file where it gets compiled into a model that I export. (Works fine.) blogSchema.js

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

var blogSchema = new mongoose.Schema({
  title:  String,
  author: String,
  }],
});

// give our schema text search capabilities
blogSchema.plugin(textSearch);

var Blog = mongoose.model('Blog', blogSchema);

exports.Blog = Blog;

This is relevant code for the server side. When the client sends a request to /search/, the socket hangs up - Got error: socket hang up and on the server side I get the How to Error: text search not enabled message.

server.js

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

var search_options = {
    project: 'title -_id'             

};

app.get('/search', function (req, res) {

    console.log("inside text search");
    Reading.textSearch('writing', search_options, function (err, output) {
        if (err) throw err;
        console.log(output);
    });

});

Thanks.

Upvotes: 0

Views: 583

Answers (1)

JohnnyHK
JohnnyHK

Reputation: 311865

You need to enable text search on the MongoDB server as described here as it's disabled by default.

Upvotes: 1

Related Questions