我想在我的Cloud Function中执行类似的操作,其中Javascript是我的脚本语言。我想从我的收藏中获取最新图像,但不知道如何在每个文档中循环。
mDatabase.collection("Users")
.document("someDocId")
.collection("Photos")
.orderBy("time", Query.Direction.DESCENDING)
.limit(1).get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
if (!Objects.requireNonNull(task.getResult()).isEmpty()){
//Loop to read each document
for (DocumentSnapshot document : task.getResult()){
//Get all data from our model and set it to corresponding view to display
holder.setAnnouncementPost(
name, annonList.get(rightPosition).getTitle(),
annonList.get(rightPosition).getDescription(),
time.substring(0,1).toUpperCase() + time.substring(1).toLowerCase(),
document.getString("thumbnail"),
annonList.get(rightPosition).isFile());
}
}
}
else
StyleableToast.makeText(context,"Error: "+ Objects.requireNonNull(task.getException()).getMessage(), R.style.mytoastError).show();
}
});
}
我需要从thumbnail
集合中获取最新文档中Photos
的值。如何使用Cloud Function做到这一点?