users collection의 각 유저의 팔로잉 목록을 collection으로 만들기 위해 아래와 같이 시도했다.
await setDoc(doc(db, `users/${user.uid}/following`, userId), {});
근데 안된다....
doc의 두번째 인자로 document를 만드려는 collection의 경로를 한 번에 주면 되는 줄 알았는데 아니었다.
그래서 구글링으로 아래의 방법을 찾아냈다.
Firebase / Firestore Add Document to Sub collection Version 9
Some reason, I just am not getting it. I want to add a new document to a sub-collection. Here is my layout as follows: Users----------- Collection UID----------- Document Lists------- Collect...
stackoverflow.com
위의 글을 토대로 아래와 같이 수정해보니 document 안에 collection이 생성되고 userId를 document id로 해서 문서가 잘 생성된다.
await setDoc(doc(db, "users", user.uid, "following", userId), {});
'프로젝트 > 트위터 클론코딩 JJack' 카테고리의 다른 글
[Firebase] Firestore storage/object-not-found 에러 해결 (0) | 2023.11.25 |
---|---|
[React] Each child in a list should have a unique "key" prop. (0) | 2023.11.24 |
[React] styled components에서 폰트 적용하기 (0) | 2023.11.23 |
[Firebase] Missing or insufficient permissions. 에러 (1) | 2023.11.20 |
[Firestore] Full Text Search 불가능 문제 (0) | 2023.11.16 |
users collection의 각 유저의 팔로잉 목록을 collection으로 만들기 위해 아래와 같이 시도했다.
await setDoc(doc(db, `users/${user.uid}/following`, userId), {});
근데 안된다....
doc의 두번째 인자로 document를 만드려는 collection의 경로를 한 번에 주면 되는 줄 알았는데 아니었다.
그래서 구글링으로 아래의 방법을 찾아냈다.
Firebase / Firestore Add Document to Sub collection Version 9
Some reason, I just am not getting it. I want to add a new document to a sub-collection. Here is my layout as follows: Users----------- Collection UID----------- Document Lists------- Collect...
stackoverflow.com
위의 글을 토대로 아래와 같이 수정해보니 document 안에 collection이 생성되고 userId를 document id로 해서 문서가 잘 생성된다.
await setDoc(doc(db, "users", user.uid, "following", userId), {});
'프로젝트 > 트위터 클론코딩 JJack' 카테고리의 다른 글
[Firebase] Firestore storage/object-not-found 에러 해결 (0) | 2023.11.25 |
---|---|
[React] Each child in a list should have a unique "key" prop. (0) | 2023.11.24 |
[React] styled components에서 폰트 적용하기 (0) | 2023.11.23 |
[Firebase] Missing or insufficient permissions. 에러 (1) | 2023.11.20 |
[Firestore] Full Text Search 불가능 문제 (0) | 2023.11.16 |