Mongoose Model.find is not a function?

后端 未结 5 925
温柔的废话
温柔的废话 2020-12-15 19:40

Spent hours trying to figure this out - I\'m adding a new Model to my app but it\'s failing with \"TypeError: List.find is not a function\". I have another model, Items, th

5条回答
  •  猫巷女王i
    2020-12-15 20:21

    Your module export is incorrect

    var mongoose = require('mongoose');
    var Schema = mongoose.Schema;
    
    var listSchema = new Schema({
        name: { type: String, default: datestring + " List" }
    });
    
    **mongoose.exports = mongoose.model('List', listSchema);** 
    

    it should be

    **module.exports = mongoose.model('List', listSchema)**
    

提交回复
热议问题