在firebase文档中添加时间戳insteard自动生成的密钥

问题描述 投票:0回答:1

我希望能够从firebase中查询最新文档,并且发现必须引用timestemp。

但是我的数据库中确实有自动生成的ID

enter image description here

我确实遇到了这个问题How to retrieve the last document in a firebase collection. I would also like to get the document fields value,发现您可以花一些时间来代替键。

我像这样向Firebase添加和更新数据:

 firebase.firestore().collection(collectionName).add({
        data: data,
        updated: getDate()
      });

firebase.firestore().collection(collectionName).doc().update({
        data: data,
        updated: getDate()
      });

所以我想知道如何使用日期作为键enter image description here

firebase google-cloud-firestore angularfire
1个回答
0
投票

如果需要指定特定的字符串作为文档ID,则不能使用add(),也不能使用没有参数的doc()。您将需要自己构建字符串,并将其传递给doc()

© www.soinside.com 2019 - 2024. All rights reserved.