Firebase Cloud功能是否有办法查询包含字段和数据的文档ID?
在Android中我会做这样的事情:
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
}
});
提前致谢!
答案 0 :(得分:1)
var usersRef = db.collection('users');
var queryRef = usersRef.where('interface_id', '==', mInterfaceId).get()
.then(snapshot => {
snapshot.forEach(doc => {
...
});
})
.catch(err => {
...
});
基本上在云函数中,您为node.js编写代码:查看文档https://firebase.google.com/docs/firestore/query-data/queries并在代码片段中选择node.js.