2017-01-27 17 views
0

TypeError:getVowels.findは関数ではないというエラーが発生し続けます。 これは、見つけ出すmongoose関数を作成する方法を学ぶ、すばらしいExpressプロジェクトです。私は間違って何をしていますか? ありがとうございます。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

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

VowelsSchemaがマングースモデルである場合、Model.find() methodがコンストラクタ自体で定義されている:

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

ではなくインスタンスの方法getVowelsとして。


注: - 例えばコンストラクタメソッドの

  • 期間(.):マングースのAPI documentationは、メソッドのタイプを区別するために2 "オペレータ" を使用しますModel.count()

    ModelType.count(function ...); 
    
  • インスタンスメソッドの

    ナンバー記号(#) - 例えばあなたが誤ってfindメソッドを使用しているModel#save()

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

を試してみてくださいおかげでジョナサン! – Bamanyi

関連する問題