为什么当我在 collection 中的文档中保存 collection 时,我在 firebase 中得到了一个很长的随机数(id 有点)

Why when I save a collection inside a doc inside a collection I got a long random number (id of somewhat) in firebase

我使用这段代码将一些数据保存到 firebase

  this.afs.collection('USERS').doc('UID').collection('Monday').add(this.submitValue);

然后在我的数据库中,我的 collection 名称和我保存的值之间有一个数字(有点 id)。

请阅读 add() 的文档。它说:

Add a new document to this collection with the specified data, assigning it a document ID automatically.

您看到的是自动生成的 ID。如果您更愿意分配自己的唯一 ID,请使用 doc(id) 生成一个引用来保存数据。

如果要设置ID,可以使用.set()方法,如下:

db.collection("cities").doc("LA").set({...})

这会在 cities 集合中生成 ID 为 'LA' 的文档。

更多信息请查看this