Mongoose Model.find is not a function?

后端 未结 5 935
温柔的废话
温柔的废话 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条回答
  •  渐次进展
    2020-12-15 20:08

    i faced this issue . to solve this , you need to understand one logic . you need to call .find as promise to model which is imported from models file.

    example:

    const member = require('..// path to model')
    
    //model initiation
    const Member = new member();
    
    exports.searchMembers = function (req,res) {
    
    
    Member.find({},(err,docs)=>{
        res.status(200).json(docs)
    })
    
    }
    

    this code dont work because i called find() to initiated schema

    code that works :

    exports.searchMembers = function (req,res) {
    
    
    member.find({},(err,docs)=>{
        res.status(200).json(docs)
    })
    
    }
    

    here i called .find() directly to imported model

提交回复
热议问题