ノードグループの結果を返す方法がわからないNode/Express APIがあります。エンドポイントを返す方法がわかりません
マイコード:
router.route('/viewed_card/:invite_id')
.get(function(req, res){
Profile.aggregate([
{$unwind:'$contacts'},
{$unwind:'$contacts.shared'},
{$match:{'contacts.shared.invite_id':req.params.invite_id}},
{$group:{
_id:null,
first_name:{$first:'$contacts.first_name'},
last_name:{$first:'$contacts.last_name'}
}}
])
})
はどのような結果を返すのですか?
"Profile.aggregate"関数の直前で "return"を実行しようとしました。
I多分このような何かかかわら:
router.route('/viewed_card/:invite_id')
.get(function(req, res){
Profile.aggregate([
{$unwind:'$contacts'},
{$unwind:'$contacts.shared'},
{$match:{'contacts.shared.invite_id':req.params.invite_id}},
{$group:{
_id:null,
first_name:{$first:'$contacts.first_name'},
last_name:{$first:'$contacts.last_name'}
}}
], function(err, result){
return result;
}
})
を何も...
コールバックでは、 'res.send(result)'と書くべきです。 – zeronone
ランタイムでサポートされている場合は、async awaitを使用することもできます。 –