
✅ Firestore Database
addDoc()
인자로 저장할 위치의 collection과 data를 받는다.
저장할 위치의 collection을 지정하기 위해 collection() 함수를 사용한다.
collection()
인자로 Firestore 인스턴스와 collection의 이름을 받는다.
const doc = await addDoc(collection(db, "tweets"), {
tweet,
order: Date.now(),
createdAt: FormatDate(),
username: user.displayName || "Anonymous",
userId: user.uid,
});
✅ Storage
ref()
파일이 업로드 될 곳의 위치를 참조한다.
const locationRef = ref(storage, `tweets/${user.uid}/${doc.id}`);
uploadBytes()
인자로 참조 위치와 데이터를 받는다.
const uploadResult = await uploadBytes(locationRef, file);
getDownloadURL()
인자로 storage ref를 받는다.
이 함수는 uploadBytes()의 return 값의 public URL을 반환한다.
const url = await getDownloadURL(uploadResult.ref);
updateDoc()
인자로 업데이트 하고 싶은 문서의 참조와 데이터를 받는다.
await updateDoc(doc, {
photoUrl: url,
});'🔥 Firebase' 카테고리의 다른 글
| Firebase - React Native iOS Setup (0) | 2026.02.26 |
|---|---|
| Firebase - Rules (0) | 2025.06.20 |
| Firebase - Hosting (0) | 2025.06.18 |
| Firebase - query(), getDocs(), onSnapshot()을 사용해 Firestore DB에서 데이터를 가져오기 (0) | 2025.06.16 |
| Firebase - 이메일 & 비밀번호 로그인과 소셜 로그인(Github) (0) | 2025.06.09 |