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

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

问题描述

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

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?

我添加数据的代码是

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".

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

截图 1

截图2截图 3

我的查询在 firestore 中为此类记录生成零结果,如下代码.如何查询所有计费节点?

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());
    });
});

推荐答案

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

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.

解决方案是通过 Firestore 控制台添加文档,因为这里的文档创建为空,或者如果在代码中添加一个字段,如果不需要,可能会再次删除它,然后文档将出现在查询中.

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天全站免登陆