0
我成功地在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);
});
});
当我控制台登录整个文件,我可以看到控制台上的“分数”领域,但“item.score”打印为“不确定”。
如何在返回结果中访问由MongoDB创建的分数?
你能展示你的物品吗?当你做'console.log(item)'时,它的外观如何? –
{_id:57bd960dd6499fef9dad4f01,cName:'XYZ',cAddress:'',__v:0,score:1.0073315117131936,contentSection:[],.....} –
“分数”是结果中返回的字段。我可以访问文档的所有其他字段并处理/打印它们 - 除了分数。 –