Is there a way in Firebase Cloud Function to query for a document ID with Field and data? In Android I would do something like this:
FirebaseFirestore fs = FirebaseFirestore.getInstances(); static final String mInterfaceId = "57ZNmAIldUPAc6ZWggvF"; fs.collection("users").whereEqualTo("interface_id", mInterfaceId).get().addOnCompleteListener(new OnCompleteListener() < @Override public void onComplete(@NonNull Tasktask) < for(DocumentSnapshot doc : task.getResult()) userId[0] = doc.getId(); if(userId.length==0) Log.e("Error: ID Not found"); else if(userId.length>1) Log.e("Error: More than one ID found"); else // Continue Process with Found ID > >);
Thanks in advance!
var usersRef = db.collection('users'); var queryRef = usersRef.where('interface_id', '==', mInterfaceId).get() .then(snapshot => < snapshot.forEach(doc =>< . >); >) .catch(err => < . >);
Basically in Cloud Functions you write code for node.js: have a look at the documentation https://firebase.google.com/docs/firestore/query-data/queries and choose node.js in the code snippets.
answered Mar 31, 2018 at 15:25 Renaud Tarnec Renaud Tarnec 82.6k 10 10 gold badges 97 97 silver badges 126 126 bronze badgesThanks Renaud. Was looking for the documentation for Firebase Cloud Functions, didn't realize that there's a node.js tab on the documentation.
Commented Apr 1, 2018 at 10:22This question is in a collective: a subcommunity defined by tags with relevant content and experts.