Firestore orderBy in Cloud Function-Javascript

时间:2018-10-28 12:25:07

标签: javascript firebase google-cloud-firestore google-cloud-functions

我想在我的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做到这一点?

0 个答案:

没有答案