简体   繁体   中英

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.

您需要按此处所述 MongoDB服务器上启用文本搜索,因为默认情况下它处于禁用状态。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM