为什么非自动生成的文档ID在Firestore控制台中用斜体显示? [英] Why are non auto-generated document Ids are in italics in Firestore console?

查看:23
本文介绍了为什么非自动生成的文档ID在Firestore控制台中用斜体显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我添加带有自己的文档ID(不是自动生成)的文档时,文档ID节点以斜体显示,如Firestore控制台中的屏幕截图所示.这背后的原因是什么?

我添加数据的代码是

 const billingRef = db
      .collection('billing/test/2017/months/11')
      .doc();

  billingRef
      .set({ name: 'ABC' })
      .then(_ => {
        console.log('saved');
      })
      .catch(err => {
        console.log(err);
      }); 

以上代码成功添加了一个节点,但以斜体添加了节点"test"和"months".

截屏1

截屏2 屏幕截图3

我的查询针对以下代码在Firestore中的此类记录产生零结果.如何查询帐单下的所有节点?

 db.collection("billing").get().then(function(querySnapshot) {
    console.log(querySnapshot.size) // this is always 0
    querySnapshot.forEach(function(doc) {
        console.log(doc.id, " => ", doc.data());
    });
}); 

解决方案

在我上面的评论之后,您将在Firestore控制台中看到对于斜体的文档,有一个小文本表示该文档不存在,不会出现在查询或快照中" ,对于非斜体,它表示该文档无数据" ,因此,直觉是当在没有任何字段的代码中创建文档时,文档为空"(子集合不计算在内).如果添加和删除了一个字段,则文档只是空的而不是空的.

由于您对帐单下的单据的查询是斜体(空"或不存在),如上面的文本所述,它们将不会出现在查询中.

解决方案是通过Firestore控制台添加文档,因为此处文档被创建为空,或者如果在代码中添加了字段,并在不需要时再次将其删除,则文档将出现在查询中. /p>

When i add a document with my own document Id (not auto generated), document Id node is in italics as shown in the screenshot from Firestore console. What is the reason behind this?

My code to add data is

const billingRef = db
      .collection('billing/test/2017/months/11')
      .doc();

  billingRef
      .set({ name: 'ABC' })
      .then(_ => {
        console.log('saved');
      })
      .catch(err => {
        console.log(err);
      });

Above code adds a node successfully, but adds node "test" and "months" in italics.

screenshot 1

screenshot 2 screenshot 3

My query yields zero results for such records in firestore, following code. How can I query all the nodes under billing?

db.collection("billing").get().then(function(querySnapshot) {
    console.log(querySnapshot.size) // this is always 0
    querySnapshot.forEach(function(doc) {
        console.log(doc.id, " => ", doc.data());
    });
});

解决方案

Following up on my comment above you will see in the Firestore console that for Documents in italic there is a small text saying "This document does not exist, it will not appear in queries or snapshots", for non-italic it says "This document has no data", so the intuition is that when the Document is created in code without any Fields then it is "null" (a subcollection does not count). If a Field is added and removed, then the Document is simply empty and not null.

Since your query for the Documents under billing are in italic ("null" or does not exist), as the text above states, they will not appear in queries.

The solution would be to either add the document through the Firestore console because here Documents are created as empty, or if in code, add a Field and maybe remove it again if not needed, then the Documents will appear in queries.

这篇关于为什么非自动生成的文档ID在Firestore控制台中用斜体显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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