Q: FireStore for Ruby - How to subscribe to document changes I would like to subscribe to changes in a firestore document in ruby using the Firestore API for Ruby 
I can get a document reference and data using the following code, but not sure how to subscribe to changes
# Firestore API
firestore = Google::Cloud::Firestore.new(project_id: 'project_id', credentials: './google-cloud-key.json')

# Get a reference to a document
ref = firestore.collection('collection_name').doc('id')

# Get the actual data in the document
snapshot = ref.get

data = snapshot.exists? ? snapshot.data : nil

# From this point on, how can I subscribe to changes in the document?


A: When I look at the Cloud Firestore documentation for Firebase for getting realtime updates it says the following: 

Note: Realtime listeners are not yet supported in the C#, Go, PHP, Python or Ruby client libraries.

So it looks like realtime updates/subscriptions are not yet supported in Ruby.

A: This feature has been recently added to the fire-store client library. 
You can use DocumentReference#listen to listen to changes in the document 
require "google/cloud/firestore"

firestore = Google::Cloud::Firestore.new

# Get a document reference
nyc_ref = firestore.doc "cities/NYC"

listener = nyc_ref.listen do |snapshot|
  puts "The population of #{snapshot[:name]} "
  puts "is #{snapshot[:population]}."
end

# When ready, stop the listen operation and close the stream.
listener.stop

