所以我正在尝试从Firestore获取结果
db.collection("dialogs")
.whereArrayContains("members", me.getId())
.get()
.continueWith(continue -> {
List<Task<DocumentSnapshot>> tasks = new ArrayList<>();
for (DocumentSnapshot snapshot : continue.getResult())
for (Object userId : (ArrayList) snapshot.get("members"))
tasks.add(db.collection("users").document(userId.toString()).get());
return tasks;
})
.addOnSuccessListener(task -> {
for (Object something : task)
Log.d("Query", "Data: " + something);
})
.addOnFailureListener(e -> Log.d("Query", "Exception: " + e));
此代码将为我提供如上所示的users
个文档,我也想要的是snapshot
的文档ID
答案 0 :(得分:0)
请注意,continue
不是文档,它是包含DocumentSnapshot结果的Task。您的DocumentSnapshot位于snapshot
中,您可以使用其getId()方法获取DocumentSnapshot的ID。
val id = snapshot.getId()