【发布时间】:2016-08-05 15:41:24
【问题描述】:
我已经在 nodejs 上构建了一个旧项目,我正在使用 MongoDb 来存储数据。 MongoDB版本是2.4
问题是我正在对集合运行文本搜索,但它从不返回任何内容,这意味着 console.log(arguments);永远不要打印任何东西
通知你们,我可以在 mongo 终端上运行 db.socialposts.runCommand( "text", { search: "accessories",limit: 1 } ) 并很快得到结果
var options, search;
options = {
limit: 1
};
search = 'accessories';
console.log(search);
SocialPost.textSearch(search, options, function(err, out) {
console.log(arguments);
return true;
});
它的架构是 var 架构;
schema = new mongoose.Schema({
entity_id: {
type: mongoose.Schema.Types.ObjectId,
required: true
},
social_id: {
type: String,
required: true
},
type: {
type: String,
required: true
},
app: {
type: String,
required: true
},
date: {
type: Date,
required: true
},
url: {
type: String,
required: true
},
post: {
type: String
},
title: {
type: String
},
image: {
type: String
},
video: {
type: String
},
hashtags: [String]
}, {
strict: 'throw'
});
而索引是
schema.index({
type: 1,
social_id: 1
});
schema.index({
type: 1,
entity_id: 1,
date: 1
});
schema.index({
title: 'text',
post: 'text'
});
【问题讨论】: