Cloud Firestore API - Class Google::Cloud::Firestore::DocumentChange (v2.16.0)

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.

Returns
  • (Boolean) — Whether the document was added.

#doc

def doc() -> DocumentSnapshot
Aliases

The document snapshot object for the data.

Returns

#document

def document() -> DocumentSnapshot
Alias Of: #doc

The document snapshot object for the data.

Returns

#modified?

def modified?() -> Boolean

Determines whether the document was modified.

Returns
  • (Boolean) — Whether the document was modified.

#new_index

def new_index() -> Integer, nil

The index in the documents array after the change.

Returns
  • (Integer, nil) — The new index

#old_index

def old_index() -> Integer, nil

The index in the documents array prior to the change.

Returns
  • (Integer, nil) — The old index

#removed?

def removed?() -> Boolean

Determines whether the document was removed.

Returns
  • (Boolean) — Whether the document was removed.

#type

def type() -> Symbol

The type of change (':added', ':modified', or ':removed').

Returns
  • (Symbol) — The type of change.