title: Query a reference field in Firestore document
body: <p>I am trying to write a function that will, after data in a document (within a Firestore 'artists' collection) is changed, will have Google Cloud Functions find all the documents in another collection ('shows') that have a reference field ('artist') that points to the document (within the 'artists' collection) that was just changed.</p>
  
  <p>I can't seem to figure out how to query the reference field.  Ive tried everything from using the ID of the artist document, to the path, to the full URL.  But I get an error in the Google Cloud Function console:</p>
  
  <pre><code>Error getting documents Error: Cannot encode type ([object Undefined]) to a Firestore Value
  </code></pre>
  
  <p>Here's a sample of my code:</p>
  
  <pre><code>exports.updateReferenceArtistFields = functions.firestore
    .document('artists/{artistId}').onWrite(event =&gt; {
    var artistRef = event.data.data();
    var artistId = artistRef.id;
    var ShowsRef = firestore.collection('shows');
    var query = ShowsRef.where('artist', '==', artistId).get()
        .then(snapshot =&gt; {
            snapshot.forEach(doc =&gt; {
                console.log(doc.id, '=&gt;', doc.data());
            });
        })
        .catch(err =&gt; {
            console.log('Error getting documents', err);
        });
  });
  </code></pre>