require"google/cloud/firestore"firestore=Google::Cloud::Firestore.new# Create a queryquery=firestore.col(:cities).order(:population,:desc)listener=query.listendo|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
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-09 UTC."],[],[],null,["# Cloud Firestore API - Class Google::Cloud::Firestore::QuerySnapshot (v3.1.0)\n\nVersion latestkeyboard_arrow_down\n\n- [3.1.0 (latest)](/ruby/docs/reference/google-cloud-firestore/latest/Google-Cloud-Firestore-QuerySnapshot)\n- [3.0.0](/ruby/docs/reference/google-cloud-firestore/3.0.0/Google-Cloud-Firestore-QuerySnapshot)\n- [2.16.1](/ruby/docs/reference/google-cloud-firestore/2.16.1/Google-Cloud-Firestore-QuerySnapshot)\n- [2.15.1](/ruby/docs/reference/google-cloud-firestore/2.15.1/Google-Cloud-Firestore-QuerySnapshot)\n- [2.14.0](/ruby/docs/reference/google-cloud-firestore/2.14.0/Google-Cloud-Firestore-QuerySnapshot)\n- [2.13.1](/ruby/docs/reference/google-cloud-firestore/2.13.1/Google-Cloud-Firestore-QuerySnapshot)\n- [2.12.0](/ruby/docs/reference/google-cloud-firestore/2.12.0/Google-Cloud-Firestore-QuerySnapshot)\n- [2.11.0](/ruby/docs/reference/google-cloud-firestore/2.11.0/Google-Cloud-Firestore-QuerySnapshot)\n- [2.10.1](/ruby/docs/reference/google-cloud-firestore/2.10.1/Google-Cloud-Firestore-QuerySnapshot)\n- [2.9.1](/ruby/docs/reference/google-cloud-firestore/2.9.1/Google-Cloud-Firestore-QuerySnapshot)\n- [2.8.0](/ruby/docs/reference/google-cloud-firestore/2.8.0/Google-Cloud-Firestore-QuerySnapshot)\n- [2.7.2](/ruby/docs/reference/google-cloud-firestore/2.7.2/Google-Cloud-Firestore-QuerySnapshot)\n- [2.6.6](/ruby/docs/reference/google-cloud-firestore/2.6.6/Google-Cloud-Firestore-QuerySnapshot) \nReference documentation and code samples for the Cloud Firestore API class Google::Cloud::Firestore::QuerySnapshot.\n\nQuerySnapshot\n-------------\n\nA query snapshot object is an immutable representation of query results,\nincluding chnages from the previous snapshot.\n\nSee [Google::Cloud::Firestore::Query#listen](/ruby/docs/reference/google-cloud-firestore/latest/Google-Cloud-Firestore-Query#Google__Cloud__Firestore__Query_listen_instance_ \"Google::Cloud::Firestore::Query#listen (method)\"). \n\nInherits\n--------\n\n- Object\n\nExample\n-------\n\n```ruby\nrequire \"google/cloud/firestore\"\n\nfirestore = Google::Cloud::Firestore.new\n\n# Create a query\nquery = firestore.col(:cities).order(:population, :desc)\n\nlistener = query.listen do |snapshot|\n puts \"The query snapshot has #{snapshot.docs.count} documents \"\n puts \"and has #{snapshot.changes.count} changes.\"\nend\n\n# When ready, stop the listen operation and close the stream.\nlistener.stop\n```\n\nMethods\n-------\n\n### #changes\n\n def changes() -\u003e Array\u003cDocumentChange\u003e\n\n**Aliases**\n\n- [#doc_changes](./Google-Cloud-Firestore-QuerySnapshot#Google__Cloud__Firestore__QuerySnapshot_doc_changes_instance_)\n- [#document_changes](./Google-Cloud-Firestore-QuerySnapshot#Google__Cloud__Firestore__QuerySnapshot_document_changes_instance_) \nThe document change objects for the query snapshot. \n**Returns**\n\n- (Array\\\u003c[DocumentChange](./Google-Cloud-Firestore-DocumentChange)\\\u003e) --- document changes.\n\n### #count\n\n def count() -\u003e Integer\n\n**Alias Of** : [#size](./Google-Cloud-Firestore-QuerySnapshot#Google__Cloud__Firestore__QuerySnapshot_size_instance_) \nReturns the number of documents in this query snapshot. \n**Returns**\n\n- (Integer) --- The number of documents.\n\n### #doc_changes\n\n def doc_changes() -\u003e Array\u003cDocumentChange\u003e\n\n**Alias Of** : [#changes](./Google-Cloud-Firestore-QuerySnapshot#Google__Cloud__Firestore__QuerySnapshot_changes_instance_) \nThe document change objects for the query snapshot. \n**Returns**\n\n- (Array\\\u003c[DocumentChange](./Google-Cloud-Firestore-DocumentChange)\\\u003e) --- document changes.\n\n### #docs\n\n def docs() -\u003e Array\u003cDocumentSnapshot\u003e\n\n**Aliases**\n\n- [#documents](./Google-Cloud-Firestore-QuerySnapshot#Google__Cloud__Firestore__QuerySnapshot_documents_instance_) \nThe documents in the snapshot. \n**Returns**\n\n- (Array\\\u003c[DocumentSnapshot](./Google-Cloud-Firestore-DocumentSnapshot)\\\u003e) --- document snapshots.\n\n### #document_changes\n\n def document_changes() -\u003e Array\u003cDocumentChange\u003e\n\n**Alias Of** : [#changes](./Google-Cloud-Firestore-QuerySnapshot#Google__Cloud__Firestore__QuerySnapshot_changes_instance_) \nThe document change objects for the query snapshot. \n**Returns**\n\n- (Array\\\u003c[DocumentChange](./Google-Cloud-Firestore-DocumentChange)\\\u003e) --- document changes.\n\n### #documents\n\n def documents() -\u003e Array\u003cDocumentSnapshot\u003e\n\n**Alias Of** : [#docs](./Google-Cloud-Firestore-QuerySnapshot#Google__Cloud__Firestore__QuerySnapshot_docs_instance_) \nThe documents in the snapshot. \n**Returns**\n\n- (Array\\\u003c[DocumentSnapshot](./Google-Cloud-Firestore-DocumentSnapshot)\\\u003e) --- document snapshots.\n\n### #empty?\n\n def empty?() -\u003e Boolean\n\nDetermines whether query results exists. \n**Returns**\n\n- (Boolean) --- Whether query results exists.\n\n### #query\n\n def query() -\u003e Query\n\nThe query producing this snapshot. \n**Returns**\n\n- ([Query](./Google-Cloud-Firestore-Query)) --- query.\n\n### #read_at\n\n def read_at() -\u003e Time\n\n**Aliases**\n\n- [#read_time](./Google-Cloud-Firestore-QuerySnapshot#Google__Cloud__Firestore__QuerySnapshot_read_time_instance_) \nThe time at which the snapshot was read. \n**Returns**\n\n- (Time) --- The time at which the documents were read.\n\n### #read_time\n\n def read_time() -\u003e Time\n\n**Alias Of** : [#read_at](./Google-Cloud-Firestore-QuerySnapshot#Google__Cloud__Firestore__QuerySnapshot_read_at_instance_) \nThe time at which the snapshot was read. \n**Returns**\n\n- (Time) --- The time at which the documents were read.\n\n### #size\n\n def size() -\u003e Integer\n\n**Aliases**\n\n- [#count](./Google-Cloud-Firestore-QuerySnapshot#Google__Cloud__Firestore__QuerySnapshot_count_instance_) \nReturns the number of documents in this query snapshot. \n**Returns**\n\n- (Integer) --- The number of documents."]]