Reputation: 2156
Here is my database.
This is my code
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 {
I have even harde coded the "Mogu..." Document ID to no effect. What is the obvious thing I am missing?
querySnapshot.documents is 0 at the last line:
for document in querySnapshot!.documents {
EDIT: It is the last query that returns 0 documents. The rest work:
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 {
Upvotes: 3
Views: 1513
Reputation: 6854
The Coinbase and Default documents in your Accounts collection don't actually exist, see non-existent docs in the console. In your screenshot, notice that the document names for Coinbase and Default are italicized and grayed out. This indicates that these documents weren't directly created but that they are on the path of a document nested deeper down which does exist.
Try setting a field value within Coinbase and Default. This should get them to appear in your query.
Upvotes: 10