簡體   English   中英

為貓鼬安裝插件-出現錯誤

[英]Installing plugins for mongoose - getting error

我正在嘗試添加第一個插件 -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);
    });

});

謝謝。

您需要按此處所述 MongoDB服務器上啟用文本搜索,因為默認情況下它處於禁用狀態。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM