Skip to content Skip to sidebar Skip to footer

Query A Reference Field In Firestore Document

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

Solution 1:

I would get the artistId from the params directly like this:

var artistId = event.params.artistId;

Example:

exports.updateReferenceArtistFields = functions.firestore
  .document('artists/{artistId}').onWrite(event => {
  var artistId = event.params.artistId;
  var showsRef = firestore.collection('shows');
  var query = showsRef.where('artist', '==', artistId).get()
      .then(snapshot => {
          snapshot.forEach(doc => {
              console.log(doc.id, '=>', doc.data());
          });
      })
      .catch(err => {
          console.log('Error getting documents', err);
      });
});

Post a Comment for "Query A Reference Field In Firestore Document"