# Cloud Firestore API - Class Google::Cloud::Firestore::QuerySnapshot (v3.2.0)

3.2.0 (latest) 3.1.1 3.0.0 2.16.1 2.15.1 2.14.0 2.13.1 2.12.0 2.11.0 2.10.1 2.9.1 2.8.0 2.7.2 2.6.6 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](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-firestore/latest/Google-Cloud-Firestore-Query#Google__Cloud__Firestore__Query_listen_instance_ "Google::Cloud::Firestore::Query#listen (method)").

## Inherits

- Object

## Example

```ruby
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>

**Aliases**

- [#doc_changes](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-firestore/latest/Google-Cloud-Firestore-QuerySnapshot#Google__Cloud__Firestore__QuerySnapshot_doc_changes_instance_)
- [#document_changes](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-firestore/latest/Google-Cloud-Firestore-QuerySnapshot#Google__Cloud__Firestore__QuerySnapshot_document_changes_instance_)
The document change objects for the query snapshot.
**Returns**

- (Array\<[DocumentChange](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-firestore/latest/Google-Cloud-Firestore-DocumentChange)\>) --- document changes.

### #count

    def count() -> Integer

**Alias Of** : [#size](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-firestore/latest/Google-Cloud-Firestore-QuerySnapshot#Google__Cloud__Firestore__QuerySnapshot_size_instance_) 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](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-firestore/latest/Google-Cloud-Firestore-QuerySnapshot#Google__Cloud__Firestore__QuerySnapshot_changes_instance_) The document change objects for the query snapshot.
**Returns**

- (Array\<[DocumentChange](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-firestore/latest/Google-Cloud-Firestore-DocumentChange)\>) --- document changes.

### #docs

    def docs() -> Array<DocumentSnapshot>

**Aliases**

- [#documents](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-firestore/latest/Google-Cloud-Firestore-QuerySnapshot#Google__Cloud__Firestore__QuerySnapshot_documents_instance_)
The documents in the snapshot.
**Returns**

- (Array\<[DocumentSnapshot](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-firestore/latest/Google-Cloud-Firestore-DocumentSnapshot)\>) --- document snapshots.

### #document_changes

    def document_changes() -> Array<DocumentChange>

**Alias Of** : [#changes](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-firestore/latest/Google-Cloud-Firestore-QuerySnapshot#Google__Cloud__Firestore__QuerySnapshot_changes_instance_) The document change objects for the query snapshot.
**Returns**

- (Array\<[DocumentChange](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-firestore/latest/Google-Cloud-Firestore-DocumentChange)\>) --- document changes.

### #documents

    def documents() -> Array<DocumentSnapshot>

**Alias Of** : [#docs](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-firestore/latest/Google-Cloud-Firestore-QuerySnapshot#Google__Cloud__Firestore__QuerySnapshot_docs_instance_) The documents in the snapshot.
**Returns**

- (Array\<[DocumentSnapshot](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-firestore/latest/Google-Cloud-Firestore-DocumentSnapshot)\>) --- document snapshots.

### #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**

- ([Query](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-firestore/latest/Google-Cloud-Firestore-Query)) --- query.

### #read_at

    def read_at() -> Time

**Aliases**

- [#read_time](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-firestore/latest/Google-Cloud-Firestore-QuerySnapshot#Google__Cloud__Firestore__QuerySnapshot_read_time_instance_)
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](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-firestore/latest/Google-Cloud-Firestore-QuerySnapshot#Google__Cloud__Firestore__QuerySnapshot_read_at_instance_) The time at which the snapshot was read.
**Returns**

- (Time) --- The time at which the documents were read.

### #size

    def size() -> Integer

**Aliases**

- [#count](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-firestore/latest/Google-Cloud-Firestore-QuerySnapshot#Google__Cloud__Firestore__QuerySnapshot_count_instance_)
Returns the number of documents in this query snapshot.
**Returns**

- (Integer) --- The number of documents.