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

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

问题描述

我有这个数据库结构:

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

当我尝试向db中添加文章(如箭头所示)时,"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.

P.S.在Firestore中,如果删除文档,则其子集合仍然存在.

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

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

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