Mongoose methods and statics

ori·2022년 7월 4일
0

TypeError: User.findByToken is not a function

// User.js
userSchema.methods.findByToken = function (token, cb) {};

// auth.js 
User.findByToken(token, (err, user) => {});

methods
methods that run from a specific instance of the Model
something that should only involve one instance
ex) 유저 비밀번호 비교하기, 유저에게 토큰 부여하기

statics
methods that run from the context of the entire Model
a query for the entire Model
ex) 토큰 값으로 해당 유저 찾기

How to Add Static Methods with Mongoose

0개의 댓글