Reference documentation and code samples for the Cloud Firestore API class Google::Cloud::Firestore::DocumentChange.
DocumentChange
A DocumentChange object represents a change to the document matching a
query. It contains the document affected and the type of change that
occurred (added, modifed, or removed).
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::DocumentChange (v3.1.0)\n\nVersion latestkeyboard_arrow_down\n\n- [3.1.0 (latest)](/ruby/docs/reference/google-cloud-firestore/latest/Google-Cloud-Firestore-DocumentChange)\n- [3.0.0](/ruby/docs/reference/google-cloud-firestore/3.0.0/Google-Cloud-Firestore-DocumentChange)\n- [2.16.1](/ruby/docs/reference/google-cloud-firestore/2.16.1/Google-Cloud-Firestore-DocumentChange)\n- [2.15.1](/ruby/docs/reference/google-cloud-firestore/2.15.1/Google-Cloud-Firestore-DocumentChange)\n- [2.14.0](/ruby/docs/reference/google-cloud-firestore/2.14.0/Google-Cloud-Firestore-DocumentChange)\n- [2.13.1](/ruby/docs/reference/google-cloud-firestore/2.13.1/Google-Cloud-Firestore-DocumentChange)\n- [2.12.0](/ruby/docs/reference/google-cloud-firestore/2.12.0/Google-Cloud-Firestore-DocumentChange)\n- [2.11.0](/ruby/docs/reference/google-cloud-firestore/2.11.0/Google-Cloud-Firestore-DocumentChange)\n- [2.10.1](/ruby/docs/reference/google-cloud-firestore/2.10.1/Google-Cloud-Firestore-DocumentChange)\n- [2.9.1](/ruby/docs/reference/google-cloud-firestore/2.9.1/Google-Cloud-Firestore-DocumentChange)\n- [2.8.0](/ruby/docs/reference/google-cloud-firestore/2.8.0/Google-Cloud-Firestore-DocumentChange)\n- [2.7.2](/ruby/docs/reference/google-cloud-firestore/2.7.2/Google-Cloud-Firestore-DocumentChange)\n- [2.6.6](/ruby/docs/reference/google-cloud-firestore/2.6.6/Google-Cloud-Firestore-DocumentChange) \nReference documentation and code samples for the Cloud Firestore API class Google::Cloud::Firestore::DocumentChange.\n\nDocumentChange\n--------------\n\nA DocumentChange object represents a change to the document matching a\nquery. It contains the document affected and the type of change that\noccurred (added, modifed, or removed).\n\nSee [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)\") and [QuerySnapshot#changes](/ruby/docs/reference/google-cloud-firestore/latest/Google-Cloud-Firestore-QuerySnapshot#Google__Cloud__Firestore__QuerySnapshot_changes_instance_ \"Google::Cloud::Firestore::QuerySnapshot#changes (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### #added?\n\n def added?() -\u003e Boolean\n\nDetermines whether the document was added. \n**Returns**\n\n- (Boolean) --- Whether the document was added.\n\n### #doc\n\n def doc() -\u003e DocumentSnapshot\n\n**Aliases**\n\n- [#document](./Google-Cloud-Firestore-DocumentChange#Google__Cloud__Firestore__DocumentChange_document_instance_) \nThe document snapshot object for the data. \n**Returns**\n\n- ([DocumentSnapshot](./Google-Cloud-Firestore-DocumentSnapshot)) --- document snapshot.\n\n### #document\n\n def document() -\u003e DocumentSnapshot\n\n**Alias Of** : [#doc](./Google-Cloud-Firestore-DocumentChange#Google__Cloud__Firestore__DocumentChange_doc_instance_) \nThe document snapshot object for the data. \n**Returns**\n\n- ([DocumentSnapshot](./Google-Cloud-Firestore-DocumentSnapshot)) --- document snapshot.\n\n### #modified?\n\n def modified?() -\u003e Boolean\n\nDetermines whether the document was modified. \n**Returns**\n\n- (Boolean) --- Whether the document was modified.\n\n### #new_index\n\n def new_index() -\u003e Integer, nil\n\nThe index in the documents array after the change. \n**Returns**\n\n- (Integer, nil) --- The new index\n\n### #old_index\n\n def old_index() -\u003e Integer, nil\n\nThe index in the documents array prior to the change. \n**Returns**\n\n- (Integer, nil) --- The old index\n\n### #removed?\n\n def removed?() -\u003e Boolean\n\nDetermines whether the document was removed. \n**Returns**\n\n- (Boolean) --- Whether the document was removed.\n\n### #type\n\n def type() -\u003e Symbol\n\nThe type of change (':added', ':modified', or ':removed'). \n**Returns**\n\n- (Symbol) --- The type of change."]]