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).
See Query#listen and QuerySnapshot#changes.
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
#added?
def added?() -> Boolean
Determines whether the document was added.
- (Boolean) — Whether the document was added.
#doc
def doc() -> DocumentSnapshot
The document snapshot object for the data.
- (DocumentSnapshot) — document snapshot.
#document
def document() -> DocumentSnapshot
The document snapshot object for the data.
- (DocumentSnapshot) — document snapshot.
#modified?
def modified?() -> Boolean
Determines whether the document was modified.
- (Boolean) — Whether the document was modified.
#new_index
def new_index() -> Integer, nil
The index in the documents array after the change.
- (Integer, nil) — The new index
#old_index
def old_index() -> Integer, nil
The index in the documents array prior to the change.
- (Integer, nil) — The old index
#removed?
def removed?() -> Boolean
Determines whether the document was removed.
- (Boolean) — Whether the document was removed.
#type
def type() -> Symbol
The type of change (':added', ':modified', or ':removed').
- (Symbol) — The type of change.