Firestore

Jan Greger Hemb & Erik Kringstad Olsen

Senior knowledge engineers at Computas

bit.ly/w-fire

Restaurant review page

tlk.io/firebase

What is Love Firebase?

Task 1

Setup Firebase & Firestore

And finally we have...

Firestore in a nutshell

  • NoSQL cloud database
  • Documents/JSON Objects
  • Highly scalable with multi region replication
  • Realtime synchronization
  • Expressive querying (for NoSQL)
  • ACID transactions
SQL Table Row Column
NoSQL Collection Document Field

NoSQL in a nutshell

(Usually) schema-less

Easy to add fields

But you need to code defensively

NoSQL means no SQL...

AAAHHH!!! Duplication!

One page in one document

Task 2

Add data to Firestore

Let's add two restaurants

Angular for new players

Components and Modules

Breaking a website up into smaller components

HTML CSS TS

TypeScript is Javascript made better

Modules are a collection of components

Angular Fire

Angular + Firebase + RxJS

Task 3

Setup Frontend and show data

(We will show you how)

Querying and
sorting data

Four operators to play with

  • Where
  • OrderBy
  • Limit
  • startAt

The where operator

  • <
  • <=
  • ==
  • >=
  • >
  • array-contains
  • array-contains-any
  • in (up to 10)

Can query across sub collections

Task 4

Filtering and sorting data

Hardcoded

All data is indexed

Never loops over all data when searching

How is data indexed?

Composite indexes

The drawbacks of Firestore

If it can't be indexed, it can't be searched

Mixing datatypes causes problems

Can't do where like

  • Where age != 25
  • Where name = "%Jan%"
  • Where age = *missing*
  • And no JOIN

Can't do "WHERE age < 25 ORDER BY name"

Document limitations

  • Max 1 write per sec per document
  • Max 1MB per document
  • Max 20k fields

Task 4.5

Filtering and sorting data

Searchbox

BREAK!

For 10 min ish

Discussion!

How can we make the "Free delivery" toggle not be exclusive when it is turned off?

Task 5

Host it on firebase!

The benefits of Firestore

Lookup-time is independent of stored data

Impossible to write slow queries

Automatically scales to match ANY usage

Automatic data synchronization

Offline support

ACID transactions

Task 6

Open and show details page

DiKO

Digital Koblingsordre

Video

Task 7

Add comments as a sub collection

Show comments

Security 🔒

Security Rules


service cloud.firestore {
	match /databases/{database}/documents {

		match /ansatt/{userId} {
			allow read: if request.auth.uid == userId;
			allow write: if request.auth.uid != null;
		}

		match /{document=**} {
			allow read, write;
		}
	}
}
					

Pricing 💰

Billed by reads, writes and deletes

Only counts the affected documents

🎉 Out of Beta! 🎉

And that's Firestore

Task

Improving on the application

  • More filtering
  • More restaurant types
  • Add voting on comments

Going even further

Add login and users

Add security rules

Add some cloud functions

bit.ly/w-fire

Data modeling