Node.js 安装mongoose插件-获取错误

Node.js 安装mongoose插件-获取错误,node.js,mongodb,mongoose,Node.js,Mongodb,Mongoose,我正在尝试添加我的第一个插件-猫鼬文本搜索 我得到一个错误:如何出错:文本搜索未启用,我无法理解 我在单独的文件中有我的模式,它被编译成我导出的模型。(很好。) blogSchema.js var mongoose = require('mongoose'); var textSearch = require('mongoose-text-search'); var blogSchema = new mongoose.Schema({ title: String, author:

我正在尝试添加我的第一个插件-猫鼬文本搜索

我得到一个错误:
如何出错:文本搜索未启用
,我无法理解

我在单独的文件中有我的模式,它被编译成我导出的模型。(很好。) 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;
 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);
    });

});
这是服务器端的相关代码。当客户端向/search/发送请求时, 套接字挂起-
得到错误:套接字挂起
在服务器端我得到
如何出错:未启用文本搜索
消息

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

});

谢谢。

您需要在MongoDB服务器上启用文本搜索,因为它在默认情况下是禁用的。

太棒了。提醒您花一部分时间阅读mongodb文档。这非常有效。非常感谢。