【发布时间】:2020-02-17 21:52:32
【问题描述】:
我一直在努力弄清楚如何从子集合中删除文档,只保留最新的 5 个文档。
我首先尝试获取子集合中的文档列表,按'updated' 日期时间戳排序。然而,这返回 null
let updates = await firestore
.collection('spots')
.doc(spot.id)
.collection('spotupdates')
.orderBy('updated','desc');
然后我尝试从列表中删除最旧的,以确保只剩下 5 个
var cntr = 0;
while(updates.docs.length > 5){
await firestore
.collection('spots')
.doc(spot.id)
.collection('spotupdates')
.doc(updates[cntr].id)
.delete();
cntr++;
}
cntr = null;
请帮忙 - 真的卡住了
【问题讨论】:
标签: javascript firebase google-cloud-firestore