개발
collection(test).doc(3) delete
•
index.ts
// Delete routine
async function deleteField() {
const id = "3";
const response = await testDelete(id);
if (response) {
return response;
} else {
throw Error("Fail to delete");
}
}
JavaScript
복사
•
firestore.ts
import { getFirestore, doc, getDoc, setDoc, deleteDoc } from "firebase/firestore";
const testDelete = async (id) => {
const db = getFirestore();
const ref = doc(db, collection, id);
try {
// Remove field from the document
await deleteDoc(ref);
return true;
} catch (e) {
return false;
}
};
export { testRead, testWrite, testDelete };
JavaScript
복사
하루 정리
TIL 작성하기
노이랩
Firestore 사용 - delete