Installing mongoose plugins - getting an error

I am trying to add mongoose-text-search to my first plugin .

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

I get an error: How to Error: text search not enabled , which I cannot understand.

I have my schema in a separate file, where it is compiled into a model that I export. (Works great.) 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 the appropriate 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 a 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.

0
source share
1 answer

You need to enable text search on the MongoDB server, as described here , since it is disabled by default.

+1
source

All Articles