[英]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);
});
});
謝謝。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.