Firebase Flashcards

1
Q

What is firebase?

A

Backend as a service

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

how to establish a connection to firebase database

A

import * as firebase from ‘firebase’;

const firebaseConfig = {
apiKey: “AIzaSyAdcTBkULme5gAMwksm7n4aSm9uRVXVkTQ”,
authDomain: “expensify-3a1e5.firebaseapp.com”,
databaseURL: “https://expensify-3a1e5.firebaseio.com”,
projectId: “expensify-3a1e5”,
storageBucket: “expensify-3a1e5.appspot.com”,
messagingSenderId: “932279113711”,
appId: “1:932279113711:web:d77772e36517d5065b881a”
};

firebase.initializeApp(firebaseConfig);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How to write to the database?

A

firebase.database().ref().set({name:’Chris’});

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to update a value in the database?

A

firebase.database(‘user’).ref(‘name’).set({name:’Chris’});

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to remove data values from database?

A

firebase.database(‘user’).ref(‘name’).remove();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to update values in the database?

A

firebase.database(‘user’).ref().update({key:value});

when updating children of a property, need to use {key/child:’value’}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How to read from the databse?

A
database.ref('propertyToAccess').once('value').then((snapshot)=>{
    const val = snapshot.val()
    console.log(val)
}).catch((error)=>{
    console.log(error)
})
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How to subsribe to a database so that it notifies you each time a change occurs

A

database.ref().on(‘value’,(snapshot)=>{
console.log(snapshot.val())
})

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How to remove a subscription to database?

A

database.ref().off((snapshot)=>{
console.log(snapshot.val())
})

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What datatype does firebase database not support?

A

Arrays

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What happens when you try and save an array in firebase database?

A

firebase turns the array into an object with array indices as keys

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

what does database.ref().push() do?

A

it creates a unique id for the element and saves the element as a child of the unique id

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

When saving and retrieving arrays from firebase database, which methods should be used

A

Storing and array

expenses.forEach((expense)=>{
database.ref(expenses).push(expense)
})

when retreiving, call forEach on snapshot

database.ref().once('value').then((snapshot)=>{
    const expenses = []
    snapshot.forEach((childSnapshot)=>{
        expenses.push({
            id:childSnapshot.key,
            ...childSnapshot.val()
        })
    })

}).catch((error)=>{
console.log(error)
})

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

name the different subcription methods

A

val()
child_removed()
child_changed()
child_added()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly