2016-07-12 7 views
1

MongoDB에서 NodeJS로 문서를 채우려고 했으므로 Schema와 post req를 작성했습니다.오브젝트가있는 몽구스 스키마

var gameSchema = new Schema({ 
     title: String, 
     developer: { 
      name: String, 
      email: String 
     }, 
     isBroadcasted: Boolean 
    }); 

그래서 나는 REQ이 스키마 감사를 채우려. 나는 그것을 실행할 때

enter image description here

router.post('/android', auth, function(req, res){ 
    // Create a new instance of the Game model 
    var game = new Game(); 
     game.title = req.body.title; 

game.developer.name = req.body.developer.name; 
game.developer.email = req.body.developer.email; 
그러나이 오류 메시지가 "형식 오류 : 부동산의 정의의 '이름'읽을 수 없습니다"가 developer.name가 존재하기 때문에 왜 이해가 안하지만 합니다.

답변

2

오류는 game.developer.name이 아니라 req.body.developer.name을 나타냅니다.
developer.name가 아닌 문자열로 중첩 된 객체로 파싱하여 매개 변수로

game.developer.name = req.body['developer.name'] 

에 라인을 변경해보십시오.

+0

고마워요! 그것은 작동합니다! –