【发布时间】:2018-03-26 09:36:53
【问题描述】:
我的 Firestore 数据库具有以下结构:
products:{ // Collection
procuct_1: { // Document
title:"",
url:""
videos:{ // Collection
video_1:{ // Document
title:"",
products:{ // Array of references
0: "/products/product_1,
1: "/products/product_2
我希望能够从 Videos Collection 中的 Array 字段获取对 Products 集合 的文档引用,以便获取此集合的某些字段的值(例如。产品名称)。
目前我使用此代码:
FirebaseFirestore firebaseFirestore = FirebaseFirestore.getInstance();
firebaseFirestore
.collection("videos")
.get()
.addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
DocumentSnapshot documentSnapshot = task.getResult();
Map<String, Object> map = documentSnapshot.getData();
for (Map.Entry<String, Object> entry: map.entrySet()){
if (entry.getKey().equals("products")){
textView.setText(entry.getValue().toString());
}
}
但是entry.getValue().toString(),返回给我这样的数组:
[com.google.firebase.firestore.DocumentReference@451d5ae8,
com.google.firebase.firestore.DocumentReference@e28cd0c]
有什么建议我可以从这个数组中获取产品集合的任何字段吗?
【问题讨论】:
标签: java android firebase google-cloud-firestore