【发布时间】:2018-06-07 16:36:43
【问题描述】:
我正在做一个小测试应用程序,我正在尝试从市场上获取所有产品。
当前的数据库架构是:
markets:[
market1: {},
market2: {},
market3: {
name: "",
products: [
item1: {},
item2: {}
]
}
]
我在 kotlin 中的代码是:
try {
db.collection("markets").document(marketId).collection("products")
.get()
.addOnCompleteListener { task ->
if (task.isSuccessful) {
var products = mutableListOf<Product>()
for (document in task.result) {
products.add(
Product(
document.id,
document.get("name").toString(),
true
)
)
}
//updateList(products)
} else {
Log.e("Getting markets", "Error getting documents.", task.exception)
}
}
}catch (e : Exception){ }
我还尝试将db.collection().document().collection() 替换为:
db.collection("markets/$marketId/products")
但它仍然返回 0 个项目,(有两个)。
任何帮助将不胜感激
【问题讨论】:
标签: firebase kotlin google-cloud-firestore