Constructor

QuerySnapshot

new QuerySnapshot()

A QuerySnapshot contains zero or more DocumentSnapshot objects representing the results of a query. The documents can be accessed as an array via the documents property or enumerated using the forEach method. The number of documents can be determined via the empty and size properties.

Properties

docChanges

read-only

Array of DocumentChange

An array of all changes in this QuerySnapshot.

docs

read-only

Array of DocumentSnapshot

An array of all the documents in this QuerySnapshot.

Example

let query = firestore.collection('col').where('foo', '==', 'bar');

query.get().then(querySnapshot => {
  let docs = querySnapshot.docs;
  for (let doc of docs) {
    console.log(`Document found at path: ${doc.ref.path}`);
  }
});

empty

read-only

boolean

True if there are no documents in the QuerySnapshot.

Example

let query = firestore.collection('col').where('foo', '==', 'bar');

query.get().then(querySnapshot => {
  if (querySnapshot.empty) {
    console.log('No documents found.');
  }
});

query

read-only

Query

The query on which you called get or onSnapshot in order to get this QuerySnapshot.

Example

let query = firestore.collection('col').where('foo', '==', 'bar');

query.limit(10).get().then(querySnapshot => {
  console.log(`Returned first batch of results`);
  let query = querySnapshot.query;
  return query.offset(10).get();
}).then(() => {
  console.log(`Returned second batch of results`);
});

readTime

string

The time this query snapshot was obtained.

Example

let query = firestore.collection('col').where('foo', '==', 'bar');

query.get().then((querySnapshot) => {
  console.log(`Query results returned at '${querySnapshot.readTime}'`);
});

size

read-only

number

The number of documents in the QuerySnapshot.

Example

let query = firestore.collection('col').where('foo', '==', 'bar');

query.get().then(querySnapshot => {
  console.log(`Found ${querySnapshot.size} documents.`);
});

Method

forEach

forEach(callback, thisArg)

Enumerates all of the documents in the QuerySnapshot.

Parameter

callback

function()

A callback to be called with a DocumentSnapshot for each document in the snapshot.

thisArg

Optional

any type

The this binding for the callback..

Example

let query = firestore.collection('col').where('foo', '==', 'bar');

query.get().then(querySnapshot => {
  querySnapshot.forEach(documentSnapshot => {
    console.log(`Document found at path: ${documentSnapshot.ref.path}`);
  });
});