我希望能够从firebase中查询最新文档,并且发现必须引用timestemp。
但是我的数据库中确实有自动生成的ID
我确实遇到了这个问题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()
});
如果需要指定特定的字符串作为文档ID,则不能使用add()
,也不能使用没有参数的doc()
。您将需要自己构建字符串,并将其传递给doc()
。