使用Timestamp列出云防火墙中的数据

时间:2018-02-05 14:50:28

标签: android firebase google-cloud-firestore

我试图通过Timestamp在Firestore中列出数据,但它不会发生。使用whereGreaterThanOrderBy

    db.collection("Users_Photos").document(uid).collection("ImageData").whereGreaterThan("image_timestamp",1506816000).orderBy("image_timestamp").addSnapshotListener(new EventListener<QuerySnapshot>() {
        @Override
        public void onEvent(QuerySnapshot documentSnapshots, FirebaseFirestoreException e) {

            if(e!=null)
            {

            }
         for (DocumentChange doc : documentSnapshots.getDocumentChanges())
         {
            if (doc.getType()==DocumentChange.Type.ADDED)
            {
                Photo photo = doc.getDocument().toObject(Photo.class);
                photosList.add(photo);
                photoListAdapter.notifyDataSetChanged();

 String name = doc.getDocument().getString("image_location");
              Log.d(TAG,name);
            }

         }

        }

    });

1 个答案:

答案 0 :(得分:1)

您没有按时间戳对数据进行排序,因为您没有使用正确的数据设置方法。正如我所见,您使用的是当前时间而不是使用服务器值时间戳。 Here是您在Cloud Firestore中正确设置时间戳的方法。如该帖子中所解释的那样,您的数据将被正确排序。