Notes

Cloud Firestore

See the Cloud Firestore docs for webarrow-up-right.

Set a document

var data = {
  name: 'Los Angeles',
  state: 'CA',
  country: 'USA',
};

// Add a new document in collection "cities" with ID 'LA'
var setDoc = db
  .collection('cities')
  .doc('LA')
  .set(data);

Data types

var data = {
  stringExample: 'Hello, World!',
  booleanExample: true,
  numberExample: 3.14159265,
  dateExample: new Date('December 10, 1815'),
  arrayExample: [5, true, 'hello'],
  nullExample: null,
  objectExample: {
    a: 5,
    b: true,
  },
};

var setDoc = db
  .collection('data')
  .doc('one')
  .set(data);

Add document with auto-generated ID

In a single-step with asynchronous access to the new ref

In two steps with synchronous access to the new ref

Update document

Note the optional merge: true option

Transactions

Batched writes

Bulk delete

Max batch size is 500 records

Get a document

Get an entire collection

Get with a where clause

List subcollections

Listen for document changes

Listen for collection changes

Stop listening

Compound queries

Valid queries

!!! INVALID QUERY AHEAD !!!

Order and limit

Valid order/limit combinations

!!! INVALID QUERY AHEAD !!!

Pagination: single-cursor

Valid pagination

Pagination: multiple-cursors

Last updated