This document does not exist and will not appear in queries or snapshots, but identically structured document works

前端 未结 5 1537
鱼传尺愫
鱼传尺愫 2021-01-12 00:45

Preface: this question is already asked here but user gave up and gave solution to first answer. This question also differs in that I have two similar collection structures,

5条回答
  •  有刺的猬
    2021-01-12 01:18

    A simple fix

    A document needs to have at least one field for it to exist. If a document only contains sub-collections, then it is said to be a virtual/non-existent document and for this reason it is not possible for it to appear in queries or data snapshots.

    consider adding a field like this

      // initialize firestoreDatabase
    
        val firestoreDatabase : FirebaseFirestore? by lazy { FirebaseFirestore.getInstance() }
    
        // set at least one field
        
        firestoreDatabase.collection("territories").
                                      document("6").
                                      set(hashMapOf(
                                  "key" to "value"))
    

    do a similar thing to any other document in your database.

提交回复
热议问题