【发布时间】:2021-03-27 00:03:58
【问题描述】:
如何批量添加到 Angular Firestore 中的集合?
以下函数尝试在集合中创建新用户:
batchCreate() {
const batch = this.firestore.collection('users').ref.firestore.batch();
this.users.forEach((user) => {
const ref: any = this.firestore
.collection('users')
// even if reference a doc like this (it doesnot works):
// const ref: any = this.firestore
// .collection('users').doc(user.id)
//this collection and documents doesnot exists on the db.
batch.set(ref, user);
});
batch.commit()
}
但是上面的逻辑是行不通的。
不知道为什么!
这个想法是创建一个集合(它在形式上不存在,但在旅途中创建),并在单个事务中推送整个用户列表,而不是单个发布请求。这可能吗?
想法是批量添加或更新集合
【问题讨论】:
-
为什么不使用事务??
-
无法引用集合。
标签: angular angularfire