[英]Installing plugins for mongoose - getting error
I'm trying to add in my first plugin - mongoose-text-search. 我正在尝试添加第一个插件 -mongoose-text-search。
https://npmjs.org/package/mongoose-text-search https://npmjs.org/package/mongoose-text-search
I'm getting the error: How to Error: text search not enabled
that I can't figure out. 我收到错误消息:
How to Error: text search not enabled
,我无法弄清楚。
I have my schema in seperate file where it gets compiled into a model that I export. 我的架构位于单独的文件中,该文件被编译成导出的模型。 (Works fine.) blogSchema.js
(工作正常。) 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;
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. 当客户端向/ search /发送请求时,套接字挂起-
Got error: socket hang up
并且在服务器端,我收到了“ How to Error: text search not enabled
消息。
server.js 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);
});
});
Thanks. 谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.