Cloud Firestore API - Class Google::Cloud::Firestore::QuerySnapshot (v2.8.0)

Reference documentation and code samples for the Cloud Firestore API class Google::Cloud::Firestore::QuerySnapshot.

QuerySnapshot

A query snapshot object is an immutable representation of query results, including chnages from the previous snapshot.

See Google::Cloud::Firestore::Query#listen.

Inherits

  • Object

Example

require "google/cloud/firestore"

firestore = Google::Cloud::Firestore.new

# Create a query
query = firestore.col(:cities).order(:population, :desc)

listener = query.listen do |snapshot|
  puts "The query snapshot has #{snapshot.docs.count} documents "
  puts "and has #{snapshot.changes.count} changes."
end

# When ready, stop the listen operation and close the stream.
listener.stop

Methods

#changes

def changes() -> Array<DocumentChange>

The document change objects for the query snapshot.

Returns

#count

def count() -> Integer
Alias Of: #size

Returns the number of documents in this query snapshot.

Returns
  • (Integer) — The number of documents.

#doc_changes

def doc_changes() -> Array<DocumentChange>
Alias Of: #changes

The document change objects for the query snapshot.

Returns

#docs

def docs() -> Array<DocumentSnapshot>
Aliases

The documents in the snapshot.

Returns

#document_changes

def document_changes() -> Array<DocumentChange>
Alias Of: #changes

The document change objects for the query snapshot.

Returns

#documents

def documents() -> Array<DocumentSnapshot>
Alias Of: #docs

The documents in the snapshot.

Returns

#empty?

def empty?() -> Boolean

Determines whether query results exists.

Returns
  • (Boolean) — Whether query results exists.

#query

def query() -> Query

The query producing this snapshot.

Returns

#read_at

def read_at() -> Time
Aliases

The time at which the snapshot was read.

Returns
  • (Time) — The time at which the documents were read.

#read_time

def read_time() -> Time
Alias Of: #read_at

The time at which the snapshot was read.

Returns
  • (Time) — The time at which the documents were read.

#size

def size() -> Integer
Aliases

Returns the number of documents in this query snapshot.

Returns
  • (Integer) — The number of documents.