Ash*_*shi 2 text-search mongoose mongodb node.js mongodb-query
我成功地在 Node.js 代码中使用 Mongoose 运行 $text 搜索。这是我使用的代码:
Model.find(
{ $text : { $search : "FindThisString"}},
{ score : {$meta : "textScore"}}
)
.sort({ score : { $meta : 'textScore'}})
.exec(function(err, results) {
_.each(results, function(item) {
//console.log(item);
console.log(item._id);
console.log(item.score);
});
});
Run Code Online (Sandbox Code Playgroud)
当我控制台记录整个文档时,我可以在控制台上看到“score”字段,但“item.score”打印为“undefined”。
如何在返回的结果中访问 MongoDB 创建的分数?
| 归档时间: |
|
| 查看次数: |
1165 次 |
| 最近记录: |