0
我想添加我的第一个插件 - 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文档。这工作完美。谢谢。 – 2013-05-13 01:42:24