1
我有用於共享照片的這個網絡應用程序。Node.js:Mongoose發生內部服務器錯誤
現在我有一個應該從following
數組的形式返回所有用戶的照片這條路線。
路線:
router.get('/getphotos',function(req, res){
var reqPhotos = [];
console.log("\n" + req.body.username + "\n");
try{
for(x =0; x < req.body.following.length; x++){
reqPhotos.push({username: req.body.following[x].username});
}
}
catch(err){
console.log(err);
}
Photo.find({username: reqPhotos}).exec(function(err, allPhotos){
if(err){console.log(err);}
else{
res.json(allPhotos);
}
});
});
但是,它給了我一個內部服務器錯誤。我從服務器獲得一個500
。
爲什麼會發生這種情況,以及如何解決它?
謝謝!
編輯:
我發現了req.body.following是不確定的。這是我是如何使用的角度稱之爲:
$scope.getPhotos = function(){
if($scope.identification){
flng = angular.copy($scope.identification.following);
flng.push($scope.identification.username);
var data = {username: $scope.identification.username, token: $scope.identification.token, following: flng}
//IDENTIFICATION HAS ALL THE INFO.
$http.get('/users/getphotos', data).success(function(response){
$scope.photos = response;
});
}
}
我認爲問題可能是在'reqPhotos.push({用戶名:req.body.following [X ]。username})';可能是以下情況之一不具備'用戶名'屬性 您應該嘗試{/ * for(x = 0; x <...)部分* /} catch(err){ console.log(err)}' –
所有這些都是... – QuikProBroNa
我看到的其他問題是'$或'語法;它應該是'{$或:[{username:reqPhotos}]}''但我並不真正看到'$ or'這個點至少應該有2個文檔,但是你只提供了一個,也許把查詢減少到' {username:reqPhotos}' –