Inflearn Community Q&A
Schema.methods와 Schema.statics의 차이
Written on
·
568
0
안녕하세요 강의 잘듣고 있습니다.
궁금한게 질문이 있습니다.
1. Schema.methods와 Schema.statics의 차이가 무었인가요?
reactnodejs
Answer 2
5
methods에서는 this가 호출한애를 가리킵니다
예를들어 asdf.findByToken 이렇게 호출했다면
this= asdf가 되구요
statics는 this가 모델 그 자체를 가리킵니다
즉 statics에서 this는 mongoose 모델을 가리킵니다
findByToken에서 statics으로 해야 하는 이유는
findOne은 mongoose 모델에서 작동하는 함수이기 때문입니다
0





