Cloud Firestore Client - Class QuerySnapshot (1.44.1)

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;
}

Namespace

Google \ Cloud \ Firestore

Methods

__construct

Parameters
Name Description
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
Type Description
bool|null

size

Returns the size of the result set.

Example:

$size = $snapshot->size();
Returns
Type Description
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
Type Description
array<Google\Cloud\Firestore\DocumentSnapshot>

getIterator

Returns
Type Description
ArrayIterator