Methods reported in mongoose are not a function.

  node.js, question

model.js

var mongoose = require('mongoose');
 
 var userSchema = new mongoose.Schema({
 username:   ...
 });
 
 userSchema.statics = {
 fetch:   ...
 bracket
 
 userSchema.methods = {
 comparePassword: function (_password, cb) {
 ...
 bracket
 bracket
 
 var user = mongoose.model('user',userSchema);
 
 module.exports = user;

controller.js

var user = require('../models/user');
 
 exports.signin = function (req, res) {
 user.findOne(...{
 user.comparePassword(password,function (err, isMatch) {
 ...
 })
 });
 bracket

May I ask the newspaper here?TypeError:user.comparePassword is not a functionWhat is the reason?

Make it clear that I do not use mongoose driver, so the following is pure speculation.

var user = require('../models/user');

souserIs amodel. This ..modelThere is a static method calledcomparePasswordIs it? Obviously not, so you useuser.comparePasswordWill fail. According to your writing, you should want to usefindOneThe of the object foundcomparePasswordMethod, this part is for you...It fell off. Check the code carefully.