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

前端 未结 5 1541
鱼传尺愫
鱼传尺愫 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:23

    I was able to fix this bug, the accepted answer currently only explains the why and does not provide a fix. Here is the code that caused the bug (for me) when I attempted to run this without a "users" collection at the root of my Firestore:

    db.collection("users").document(currentUserUID).collection("groups").addDocument(data: [
            "groupID": newGroup.documentID,
            "userAddDate": NSDate()
        ])
    

    The currentUserUID document that was created was throwing the 'Document does not exist' virtual bug. I copied the currentUserUID and deleted the users collection and virtual UserUID document.

    I then created a new 'users' collection at the root node and pasted in the value I had copied for the userUID with a bogus field.

    Then when I re-ran the above snippet of code, the "groups" collection and document were re-added no problem :)

提交回复
热议问题