Node.JS / Mongoose / Express -> Object has no method "findAll" Node.JS / Mongoose / Express -> Object has no method "findAll" mongoose mongoose

Node.JS / Mongoose / Express -> Object has no method "findAll"


I think you have a few problems here:

  1. Your schema's instance methods should be defined on MemberSchema.methods (not .method).
  2. A method like findAll that returns instances should be defined as a static method of the schema (on MemberSchema.statics) instead of an instance method.
  3. You should be exporting MyModel, not a new MyModel instance of it as you are now. module.exports = MyModel;
  4. route.js should not be using new in its require as you want the MyModel class to be available to the file, not an instance of it.


for the find function the syntax usually is

<modelname>.find({conditions},function(err, results){//use the results});

and if u don't have any specific conditions and want to find all, you can just give empty object in the conditions {}

<modelname>.find({},function(err, results){//use the results});

and for the schema, an example

const articleSchema = {  title: String,  content: String};// to create a new model named Articleconst Article = mongoose.model("article",articleSchema);