Cloud Firestore Client - Class QuerySnapshot (1.27.3)

Reference documentation and code samples for the Cloud Firestore Client class QuerySnapshot.

Represents the result set of a Cloud Firestore Query.

Example:

use Google\Cloud\Firestore\FirestoreClient;

$firestore = new FirestoreClient();
$collection = $firestore->collection('users');
$query = $collection->where('age', '>', 18);

$snapshot = $query->documents();
// Snapshots can be iterated with foreach:
foreach ($snapshot as $user) {
    echo $user['name'] . PHP_EOL;
}

Methods

__construct

Parameters
NameDescription
query Google\Cloud\Firestore\Query

The Query which generated this snapshot.

rows array<Google\Cloud\Firestore\DocumentSnapshot>

The query result rows.

isEmpty

Check if the result is empty.

Example:

$empty = $snapshot->isEmpty();
Returns
TypeDescription
bool|null

size

Returns the size of the result set.

Example:

$size = $snapshot->size();
Returns
TypeDescription
int|null

rows

Return the formatted and decoded rows. If the stream is interrupted, attempts will be made on your behalf to resume.

Example:

$rows = $snapshot->rows();
Returns
TypeDescription
array<Google\Cloud\Firestore\DocumentSnapshot>

getIterator

Returns
TypeDescription
ArrayIterator