Upgrade to Pro — share decks privately, control downloads, hide ads and more …

FirestoreのN:N関連の設計の話

hayashiki
January 20, 2019

 FirestoreのN:N関連の設計の話

hayashiki

January 20, 2019
Tweet

More Decks by hayashiki

Other Decks in Technology

Transcript

  1. Firebaseで提供はしている 例: function listAllUsers(nextPageToken) { // List batch of users,

    1000 at a time. admin.auth().listUsers(1000, nextPageToken) .then(function(listUsersResult) { listUsersResult.users.forEach(function(userRecord) { console.log("user", userRecord.toJSON()); }); if (listUsersResult.pageToken) { // List next batch of users. listAllUsers(listUsersResult.pageToken) } }) }
  2. コールバック // googleログインをクリックしたときに動作する関数例 handleLogin = async () => { //

    google login const authData = await this.database.googleLogin(); // userInfo に格納 firestore.doc(`userInfo/${authData.uid}`).set( { id: authData.uid, state: 'active', email: authData.email } ) }
  3. Firebase Authenticationトリガー https://firebase.google.com/docs/functions/auth‑events?hl=ja exports.createUser = functions.firestore .document("users/{userId}") .onCreate((snap, context) =>

    { let { email, name } = snap.data() let uid = context.params.userId return admin .auth() .createUser({ uid, email, displayName: name, }) })
  4. firestore-root | --- posts (collections) | | | --- postId

    (document):0cCIGH6Dunw2TcLubvzS | | | --- title: "Question Title" | | | --- body: "Question Title" | | | --- tags (subCollections) | | | --- tagId: "0cCIGH6Dunw2TcLubvzS"(docume | | | --- tagId (document) | --- tags (collections) | | | --- tagId (document): 0cCIGH6Dunw2TcLubvzS | | | --- name: "JS" | | | --- posts (subCollections) | | | --- postsId: "0cCIGH6Dunw2TcLubvzS"(docu