dmstn05573405
@dmstn05573405
Reviews Written
2
Average Rating
5.0
Posts
Q&A
firebase filterling ๊ด๋ จ ์ง๋ฌธ
๊ทธ๋ฆฌ๊ณ createAt์ date๋ก ๋ณํํด์ client ์ ๋๊ฒจ์คฌ๋๋ฐ, ํฐ๋ฏธ๋์ ISO๋ก ์ฐํ๋๋ฐ ๋ฐ์ดํฐ๋ timestamp string์ผ๋ก ๋ค์ด ์ค๋๋ฐ, ์ด ๋ถ๋ถ ํน์.. ์ ๊ทธ๋ฌ๋์ง ์์ค๊น์...?> ใ ใ ๊ตฌ๊ธ๋งํด๋ ์ ์๋์ค๋ค์ ใ ใ (์ฌ์ง)(์ฌ์ง)
- Likes
- 0
- Comments
- 3
- Viewcount
- 568
Q&A
firebase filterling ๊ด๋ จ ์ง๋ฌธ
Query: { products: async (parent, { cursor = "", showDeleted = false }, info) => { //Admin์์๋ ๋ค ๋ณด์ฌ์ฃผ๊ณ , ์ผ๋ฐ ํ์ด์ง์์๋ createdAt์ด ์๋ ๊ฒ๋ค๋ง ๋ณด์ฌ์ฃผ๊ธฐ. //context ์ ๋ด๊ธด DB ํ์ํ ๋๋ง๋ค ๋ถ๋ฌ์ค๊ธฐ. const products = collection(db, "products"); //products collection const queryOptions: any[] = [orderBy("createdAt", "desc")]; //filterOptions if (cursor) queryOptions.push(startAfter(cursor)); /** * cursor ๊ธฐ๋ณธ๊ฐ ="" (์ด๊ธฐ ์ง์ ํ์ ๋) => ์กฐ๊ฑด์ ๋ค์ด์ค์ง ์์ * cursor ๋ก ๋ง์ง๋ง ์์ดํ ID๊ฐ ๋ค์ด์์ ๋ => ์กฐ๊ฑด์ ๋ค์ด์ด. * @look queryOptions= [orderBy("createdAt", "desc"),startAfter(cursor)] * @see ์ง๋ฌธ * @question ๋ค์ด์ค๋ ๊ฐ์ ํด๋น ์์ดํ ์ ID ์ธ๋ฐ, ๊ธฐ์ค์ createdAt์ด ๋๋๊ฒ ์๋๊ฐ์? * */ if (!showDeleted) queryOptions.unshift(where("createdAt", "!=", null)); // showDeleted = false ์ผ ๋, ์ญ์ ๋๊ฒ ์ ์ธํ๊ณ ๋ณด์ฌ์ค (์ด ์กฐ๊ฑด์ด ์ ค ์ฒ์ ์ ์ฉ ๋จ) const q = query(products, ...queryOptions, limit(PAGE_SIZE)); const snapshot = await getDocs(q); const data: DocumentData[] = []; snapshot.forEach((doc) => { // ID๊ฐ ์๊ธฐ๋๋ฌธ์ ๊ฐ์ ๋ก ID ๋ฃ์ด์ค. data.push({ id: doc.id, ...doc.data(), createdAt: doc.data().createdAt ? doc.data().createdAt.toDate() : undefined, }); }); return data; },
- Likes
- 0
- Comments
- 3
- Viewcount
- 568




