【发布时间】:2016-07-24 16:06:08
【问题描述】:
我正在使用 Node、Express、Mongoose 和 Mongodb 为 Web 应用程序创建后端。我正在尝试对具有名称字段和标签数组的某些用户配置文件运行部分搜索,以便“re”将返回带有标签数组的配置文件或名称包含“red”和“blueish”的配置文件将返回带有包含“蓝色”的标签数组或名称
我找到了添加正则表达式的语法。大致如下:
Profile.find(.0
{ "tags": { "$regex": "re", "$options": "i" } },
function(err,docs) {
str = JSON.stringify(docs, null, 4);
console.log(str)
}
);
我也在尝试对它们进行评分并对结果进行排序。我发现另一个堆栈溢出帖子是这样的:
Profile.find({ "$text": { "$search": input } })
.select({ "score": { "$meta": "textScore" } })
.sort({ "score": { "$meta": "textScore" } })
.exec(function(err,result) {
str = JSON.stringify(result, null, 4);
console.log(str)
}
);
但是在阅读了文档之后,我仍然对如何结合这两个概念感到模糊。有小费吗?
【问题讨论】:
标签: node.js mongodb express search mongoose