study: 리네다기 | 8장 - firebase firestore

Lumpen·2023년 5월 10일
0

Study

목록 보기
75/92

firestore 는 noSQL 로 문서와 컬렉션이라는 개념이 있다
문서는 키-값 쌍의 자료형으로 각 문서는 고유 ID 가 있다
문서들의 집합이 컬렉션

SQL로 치면 컬렉션이 DB, 문서가 table 과 비슷한 느낌인것 같다

import firestore from '@react-native-firebase/firestore';

export const usersCollection = firestore().collection('users');

export function createUser({id, displayName, photoURL}) {
  return usersCollection.doc(id).set({
    id,
    displayName,
    photoURL,
  });
}

export async function getUser(id) {
  const doc = await usersCollection.doc(id).get();
  return doc.data();
}

usersCollection 에서 add 메서드를 사용하면 firestore 에서 생성해주는 고유 아이디 값을
얻을 수 있다

profile
떠돌이 생활을 하는. 실업자는 아니지만, 부랑 생활을 하는

0개의 댓글