【发布时间】:2020-08-29 11:28:01
【问题描述】:
我正在尝试将文档添加到我的用户集合中的数组 studyList 中。
所以我有一个集合用户,其中我有名字等.. 和 studyList。
当我点击购买 DocumentItemComponent 的按钮时,我想将该文档添加到这个 studyList 数组中。
我的代码部分工作是因为它将文档添加到数组中,但是当我单击另一个文档时,它会更改第一个文档,它不会添加另一个文档。
这是我添加函数的代码:
addToStudyList(user) {
const userRef: AngularFirestoreDocument<any> = this.afs.doc(`users/${user.id}`);
const data: UserInterface = {
studyList: [{
title: this.document.title,
language: this.document.language,
description: this.document.description,
cover: this.document.cover,
category: this.document.category,
field: this.document.field,
id: this.document.id,
author: this.document.userUid,
urlDocument: this.document.urlDocument
}]
}
return userRef.set(data, {merge: true});
}
你能帮帮我吗? 谢谢!祝你有美好的一天!
【问题讨论】:
标签: arrays angular firebase collections push