2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

firestore+nuxt入門

Last updated at Posted at 2019-10-05

この記事の目的

firebaseのfistoreの読み書きの基本をまとめる

firestoreのデータモデル

memo-61.jpg

  • コレクション・・・tableのようなもの
  • ドキュメント・・・レコードのようなもの
  • データ・・・値のようなもの

読み書きの仕方

var db = firebase.firestore();
// dbに初期化したfireastoreを代入
db.collection("users").add({
    first: "Ada",
    last: "Lovelace",
    born: 1815
})
.then(function(docRef) {
    console.log("Document written with ID: ", docRef.id);
})
.catch(function(error) {
    console.error("Error adding document: ", error);
});
// addでusersコレクションにデータをいれていく

thenは処理が成功した際の処理。chatchは失敗してエラーが出た際の処理。

データの書き込み

  • データベースの作成
  • ルールの作成
  • firestoreの初期化
  • addでcollectionの追加

書き込み(set、add、update)

  • set・・・データを追加、もしすでにデータがあったら上書き
  • update・・・既存のデータを更新
  • add・・・新しいドキュメント、データを追加する

データの取得

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?