2017-01-27 3 views
0

TypeError : getVowels.find가 함수가 아닙니다.라는 오류가 계속 발생합니다. 찾는 몽구스 기능을 만드는 방법을 배우는 탐욕스러운 프로젝트입니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까? 미리 감사드립니다. VowelsSchema 경우Express TypeError 객체가 함수가 아닙니다.

var express = require('express'); 
var router = express.Router(); 
var mongoose = require('mongoose'); 

var VowelsSchema = require('../models/vowels'); 

// connect to our database 
mongoose.createConnection('mongodb://127.0.0.1:27017'); 

module.exports = router; 

router.get('/', function(req, res) { 
    var getVowels = new VowelsSchema();  

    getVowels.find(function(err, vowels) { 
    if (err) { 
     res.send(err); 
    } 
    res.json(vowels); 
    }); 
}); 

답변

1

Model#save() 당신은 잘못 find 방법을 사용하고 있습니다. instance of your model에서 작동하지 않지만 model에서 작동합니다.

그래서 대신 getVowel.find(function(err,vowels){...})의이

VowelsSchema.find({},function(err,vowels){//its always a good practice to ue {} in find 
    if (err) { 
     res.send(err); 
    } 
    res.json(vowels); 
}); 
+0

고마워요. 내가 잘못하고있는 것입니다. – Bamanyi

1

Model.find() method 생성자는 자체 정의된다 몽구스 모델 :

VowelsSchema.find(function (err, vowels) { ... }); 

보다는 인스턴스의 방법 getVowels있다.


참고 : - 예를 들어, 생성자 메서드에 대한

  • 기간 (.) : 몽구스의 API documentation는 방법의 유형을 구분하기 위해 2 "사업자"를 사용 예를 들어, - 인스턴스 메소드에 대한 Model.count()

    ModelType.count(function ...); 
    
  • 번호 표시 (#)

    var instance = new ModelType({ ... }); 
    instance.save(function ...); 
    
+0

감사 조나단 시도! – Bamanyi

관련 문제