Reputation: 1779
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<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
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!
Upvotes: 3
Views: 6643
Reputation: 83191
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.
Upvotes: 5