为猫鼬安装插件-出现错误 [英] Installing plugins for mongoose - getting error

查看:50
本文介绍了为猫鼬安装插件-出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

我遇到错误:How to Error: text search not enabled,我无法弄清楚.

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

我的架构存放在单独的文件中,该文件被编译成导出的模型. (工作正常.) blogSchema.js

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;

这是服务器端的相关代码.当客户端向/search/发送请求时, 套接字挂起-Got error: socket hang up,在服务器端,我得到了 How to Error: text search not enabled消息.

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

});

谢谢.

推荐答案

您需要按照

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

这篇关于为猫鼬安装插件-出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆