0

I'm trying to get the uid of the user, the uid is in the path of the document that has been changed but not sure how to extract it from the path?

exports.watchTodos = functions.firestore.document('users/{uid}/todos/{docId}')
        .onUpdate(async (snap, context) => {
            // get the uid of the user

  }
Gerry
  • 1,159
  • 1
  • 14
  • 29
  • Does this answer your question? [Firestore - Cloud Functions - Get uid](https://stackoverflow.com/questions/47129512/firestore-cloud-functions-get-uid) – sllopis Jun 17 '20 at 10:01
  • @sllopis Thanks but, I had a look at that but it doesn’t. It is talking about the case where the uid is not in the path – Gerry Jun 17 '20 at 10:58

1 Answers1

0

This is what you need:

exports.watchTodos = functions.firestore.document('users/{uid}/todos/{docId}')
        .onUpdate(async (snap, context) => {
            const pathId = context.params.uid;

  }
sllopis
  • 2,292
  • 1
  • 8
  • 13
  • Great thanks, also I'm new to cloud functions so wondering how would I get the done property (bool) which is on the document and check if it's true or false? Thanks – Gerry Jun 17 '20 at 12:09
  • I've tried: if(snap.after.data().done){ console.log('is done') }, but it doesn't ever execute, but if I print snap.after.data().done is true. – Gerry Jun 17 '20 at 12:17