강의

멘토링

커뮤니티

Inflearn Community Q&A

ehghksvjscl's profile image
ehghksvjscl

asked

Node and React series that you can learn by following - Basic lecture

Node React Basics Lecture #14 Logout Function

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

이거 이전강의 질문답변에 있습니다!

ehghksvjscl's profile image
ehghksvjscl

asked

Ask a question