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에서 만든 점수에 어떻게 액세스합니까?
아이템을 보여 주실 수 있습니까? –
{_id : 57bd960dd6499fef9dad4f01, cName : 'XYZ', cAddress : '', __v : 0, 점수 : 1.0073315117131936, contentSection : [], .....} –
"score"는 결과에 반환 된 필드입니다. 나는 점수를 제외한 문서의 다른 모든 필드에 액세스하여 인쇄/인쇄 할 수 있습니다. –