Node.JS / Mongoose / Express -> Object has no method "findAll"
I think you have a few problems here:
- Your schema's instance methods should be defined on
MemberSchema.methods
(not.method
). - A method like
findAll
that returns instances should be defined as a static method of the schema (onMemberSchema.statics)
instead of an instance method. - You should be exporting
MyModel
, not anew MyModel
instance of it as you are now.module.exports = MyModel;
route.js
should not be usingnew
in itsrequire
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);