我试图在另一个集合中复制一个文档的内容,但我做不到。这是我的密码
首先,我得到了以下引用:
this.pollRef = this.afs.collection('polls').doc(pollId);然后,我尝试用以下代码将其复制到另一个集合中:
//Option 1 copy the documentRef
var idBefore = this.afs.createId();
console.log(idBefore);
const datas = { name: 'hola' }
this.afs.collection('rooms').doc(idBefore).set(datas);
var idBefore2 = this.afs.createId();
this.afs.collection('rooms')
.doc(idBefore)
.collection('poll')
.doc(idBefore2)
.set(this.pollRef);它抛出此错误:
错误:使用无效数据调用的函数DocumentReference.set()。数据必须是一个对象,但它是:自定义的AngularFirestoreDocument对象。
发布于 2019-02-11 15:18:15
我终于能解决了。我分享这个问题的答案
var idBefore = this.afs.createId();
console.log(idBefore);
const datas = { name: 'hola' }
this.afs.collection('rooms').doc(idBefore).set(datas);
var pollId: string = this.roomForm.get('pollId').value;
const x = this.pollsService.getPoll(pollId);
x.subscribe(poll => {
//this.spinnerService.hide();
const pollData = poll.payload.data() as Poll;
pollData["id"] = pollId;
this.PollModel = pollData;
console.log(this.PollModel);
this.afs.doc(`rooms/${idBefore}`).collection('polls').add(this.PollModel)
});
https://stackoverflow.com/questions/54632630
复制相似问题