Firestore 文档/子集合不存在 [英] Firestore document/subcollection is not existing

查看:25
本文介绍了Firestore 文档/子集合不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个数据库结构:

Firestore-root
|
--- sites (collection)
|     |
|     --- common (document)
|            |
|            --- //templates (collection)
|            |
|            --- //menus (collection)
|            |
|            --- //articles (collection) <----
|     --- other (document)
|            |
|            --- //articles (collection)

当我尝试将文章添加到数据库(如箭头所示)时,common"和other" - 文档为斜体,因此不存在.

When I try to add articles to the db (shown by the arrow) the "common" and the "other" - document is in italic and therefore doesn't exist.

我尝试添加时的代码:优先级是普通的,类型是文章.

My code when i try to add: priority is common, type is articles.

def documentReference = firestoreClient.databaseReference.collection(siteName).document(priority).collection(TYPE).document(key)
documentReference.set(article)

这是控制台:

这是构建我的数据库的糟糕方法还是有快速修复的方法?

Is this a bad way to structure my db or is there a quick fix?

我曾尝试先创建子集合,但没有成功!

I have tried to create the sub collections first but without any luck!

推荐答案

Firebase 控制台并未指示您已删除通用"和其他"文档.它告诉你它只是存在.这些文档不存在是因为您根本没有创建它们.您所做的只是只是在一个本来就不存在的文档下创建一个子集合.换句话说,它只是为该集合中的文档保留"一个 id,然后在其下创建一个子集合.通常,您应该只创建实际确实存在的文档的子集合,但这是文档不存在时的样子.

The Firebase Console isn't indicating you that the "common" and the "other" documents are deleted. It is telling you that it just does not exist. Those documents do not exist because you didn't create them at all. What you did do, was only to create a subcollection under a document that never existed in the first place. With other words, it merely "reserves" an id for a document in that collection and then creates a subcollection under it. Typically, you should only create subcollections of documents that actually do exist but this is how it looks like when the document doesn't exist.

要记住的一件事是,在 Cloud Firestore 中,文档和子集合不像文件系统文件和目录那样工作.如果在文档下创建子集合,它不会隐式创建任何父文档.子集合与父文档没有任何关联.

One thing to remember, in Cloud Firestore documents and subcollections don't work like filesystem files and directories. If you create a subcollection under a document, it doesn't implicitly create any parent documents. Subcollections are not tied in any way to a parent document.

以斜体显示的文档 ID 不一定会被删除".它们以这种方式显示,因为该文档不存在.换句话说,该位置没有物理文档该位置下有其他数据.

Document ids shown in italics are not necessarily "deleted". They are shown that way because the document does not exist. With other words, there is no physical document at that location but there is other data under the location.

如果你想纠正它,你必须至少写一个可以保存值的属性.

If you want to correct that, you have to write at least a property that can hold a value.

附言在 Firestore 中,如果您删除一个文档,它的子集合仍然存在.

P.S. In Firestore, if you delete a document, its subcollections still exist.

这篇关于Firestore 文档/子集合不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆