๋ณต์ต - USER PROFILE
๋ณต์ต - WEBPACK
์ค์ ์ฝ๋๋ github์ ์ฌ๋ฆผ(wetube_v2)
๐ก user.save() ํ ๋๋ง๋ค ํจ์ค์๋๊ฐ ํด์ฑ๋๋ ๋ฌธ์ ํด๊ฒฐ
this.isModified("password")
๋ฅผ ์ถ๊ฐํด user.save()๋ฅผ ์ฌ์ฉํด๋ ๋น๋ฐ๋ฒํธ๊ฐ ๋ณ๊ฒฝ๋ ๋๋ง pre hook์ด ์คํ๋๋๋ก ํจ
!this.socialOnly
๋ฅผ ์ถ๊ฐํด github ์ ๋ณด๋ฅผ ๋ฐํ์ผ๋ก ๊ณ์ ์์ฑ ์์๋ user.save()๋ฅผ ์ฌ์ฉํด๋ pre hook์ด ์คํ๋์ง ์๋๋ก ํจ โ (๋ณต์ตํ๋ฉด์ ์๋กญ๊ฒ ์ถ๊ฐํ ๋ถ๋ถ)// User.js userSchema.pre("save", async function () { if (!this.socialOnly && this.isModified("password")) { this.password = await bcrypt.hash(this.password, 5); } });
๐ก populated fields์ sort() ์ ์ฉ (๋ณต์ตํ๋ฉด์ ์๋กญ๊ฒ ์ถ๊ฐํ ๋ถ๋ถ)
const user = await User.findById(id).populate({ path: "videos", options: { sort: { createdAt: "desc" }, }, });