这是我的数据库。
这是我的代码
let db = Firestore.firestore()
let defaults = UserDefaults.standard
let userId: String! = defaults.string(forKey: "UserUUID")
db.collection("Portfolios")
.whereField("users." + userId, isEqualTo: true)
.limit(to: 1)
.getDocuments() { (querySnapshot, err) in
if let err = err {
print("Error getting documents: \(err)")
} else {
for portfolioDocument in querySnapshot!.documents {
print("Portfolio: \(portfolioDocument.documentID) => \(portfolioDocument.data())")
let portRef = db.collection("Portfolios").document("portfolioDocument.documentID")
portRef.getDocument { (document, error) in
if let document = document {
print("Document data: \(document.data())")
portRef.collection("Accounts").getDocuments() { (querySnapshot, err) in
if let err = err {
print("Error getting documents: \(err)")
} else {
var docs:[DocumentSnapshot] = []
for document in querySnapshot!.documents {
我甚至将“Mogu ......”文档ID编码为无效。我错过了哪些显而易见的事情?
querySnapshot.documents在最后一行为0:
for document in querySnapshot!.documents {
编辑:这是返回0个文档的最后一个查询。其余工作:
no, that has no effect on the top level as that is successful. It is the last query that is brings 0 documents: portRef.collection("Accounts").getDocuments() { (querySnapshot, err) in
if let err = err {
print("Error getting documents: \(err)")
} else {
var docs:[DocumentSnapshot] = []
for document in querySnapshot!.documents {
答案 0 :(得分:3)
您的帐户集合中的Coinbase和默认文档实际上并不存在。在屏幕截图中,请注意Coinbase和Default的文档名称是斜体并显示为灰色。这表明这些文档没有直接创建,但是它们位于更深层嵌套的文档的路径上。
尝试在Coinbase和Default中设置字段值。这应该会使它们显示在您的查询中。