【问题标题】:How to get data from fields, not entire document. Firestore [duplicate]如何从字段中获取数据,而不是整个文档。 Firestore [重复]
【发布时间】:2019-08-12 12:32:19
【问题描述】:

我正在尝试从我的 firebase firestore 上的字段中获取数据,但不是整个文档。 Fields that i want

这是获取整个文档的代码。

db.collection("Reminder").get()
            .addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
                @Override
                public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
                    if (!queryDocumentSnapshots.isEmpty()) {
                        List<DocumentSnapshot> list = queryDocumentSnapshots.getDocuments();

                        for (DocumentSnapshot d : list) {
                            dbReminder p = d.toObject(dbReminder.class);
                            p.setId(d.getId());
                            remtasklist.add(p);
                        }
                        adapter.notifyDataSetChanged();

                    }
                }
            });

提前致谢。 编辑:我更新了收藏图片。 Collection

【问题讨论】:

  • 请在该屏幕截图中向您展示更多 Firebase 集合
  • 没有 API 只能获取特定字段。您必须阅读整个文档才能获得该文档中的任何字段。
  • @ManojPerumarath 现在更新了一张照片
  • T@DougStevenson 这是一个与android相关的问题,不是一个快速的问题。,它怎么可能是重复的。
  • 你需要查询集合,获取你需要的具体用户

标签: android firebase google-cloud-firestore


【解决方案1】:

您可以从 documentSnapshot 中获取特定字段。

 String location = documentSnapshot.getString("inLocation");
 String time = documentSnapshot.getString("time");//assuming time here is string
 String title = documentSnapshot.getString("title");

【讨论】:

  • 如果您不想使用循环,则必须更好地编写查询db.collection("Reminder").document("mydocumenthere");。这样,您可以直接从文档快照中获取字段。
  • 好的,谢谢它现在有效,再次感谢您
猜你喜欢
  • 2019-11-27
  • 1970-01-01
  • 2021-11-05
  • 1970-01-01
  • 2021-06-24
  • 1970-01-01
  • 1970-01-01
  • 2020-09-06
  • 1970-01-01
相关资源
最近更新 更多