I am having a weird issue where our parent document is being marked as deleted. I am inserting a new document like this:
const userDoc = admin.firestore().doc(`/user_bundles/${context.params.userId}/bundles/${chargeRecord.course_id}/media/${chargeRecord.media_type}`);
return userDoc.set(bundleDoc.data(), { merge: true });
However, the "chargeRecord.course_id" document is being marked as deleted, resulting in empty queries.
I've ran into another question and answer where it explained this can happen when the sub collection is deleted. But to be clear we have not deleted this document. It was newly created for the user.
Documents and subcollections don't work like filesystem files and directories.
Creating a subcollection organized under a document ID doesn't implicitly create any parent documents. Subcollections are not tied in any way to a parent document, other than through the organization you impose. It's perfectly valid to organize subcollection under a document id that doesn't exist.
Document IDs shown in italics are not necessarily "deleted". They are shown that way because the don't exist, and maybe never existed - you can't tell the difference.
If you want any document to exist, you have to write some code to create it and give it some fields. If you never explicitly create a document, then it never exists.
If you delete a document, its subcollections still exist.