【问题标题】:Installing plugins for mongoose - getting error为猫鼬安装插件 - 出现错误
【发布时间】:2013-05-06 22:55:12
【问题描述】:

我正在尝试添加我的第一个 插件 - mongoose-text-search。

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

我收到错误消息:How to Error: text search not enabled,我无法弄清楚。

我的架构在单独的文件中,它被编译成我导出的模型。 (工作正常。) 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 消息。

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

});

谢谢。

【问题讨论】:

    标签: node.js mongodb mongoose


    【解决方案1】:

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

    【讨论】:

    • 太棒了。提醒您花时间阅读 mongodb 文档。那工作得很好。谢谢。
    猜你喜欢
    • 2018-12-16
    • 2015-08-21
    • 2014-07-27
    • 2017-06-14
    • 2019-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-02
    相关资源
    最近更新 更多