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

I'm trying to pass a method from my model.js to my route.js.. And my route doesn't find any method ! I searched a solution and tested a lot of codes, without success.

I'm a beginner in Node so sorry if it's a stupid error.

This is a part of my code :


Route.js

var mongoose    = require('mongoose');
var membersModel = new require('../models/MemberModel');

// Member list page
exports.list = function(req, res){
    membersModel.findAll(function(err, docs){
        res.render('list.jade', { title: 'My Registration App - Member list', member:  docs });
    });
};

MemberModel.js

var mongoose = require('mongoose'),
    Schema = mongoose.Schema,
    ObjectId = Schema.ObjectId;

    // Open DB connection


var MemberSchema = new Schema({
    id        : ObjectId,
    title     : { type: String, required: true, enum: ['Mr', 'Mrs', 'Mme', 'Miss'] },
    lastname  : { type: String, required: true, uppercase: true, trim: true},
    firstname : { type: String, required: true},
    mail      : { type: String, trim: true, index: { unique: true, sparse: true } },
    date      : Date
});

// ...

MemberSchema.method.findAll = function (callback) {
  Members.find(function (err, member) {
        callback(null, member)
  });
};

var conn = mongoose.createConnection('mongodb://localhost/members');
var MyModel = conn.model('Members', MemberSchema);
var instanceMember = new MyModel;

module.exports = instanceMember;

Thanks for the time passed helping me. If you want other informations, tell me !

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.