首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用angularfire2将文档复制到另一个集合

使用angularfire2将文档复制到另一个集合
EN

Stack Overflow用户
提问于 2019-02-11 14:22:53
回答 1查看 369关注 0票数 0

我试图在另一个集合中复制一个文档的内容,但我做不到。这是我的密码

首先,我得到了以下引用:

代码语言:javascript
复制
this.pollRef = this.afs.collection('polls').doc(pollId);

然后,我尝试用以下代码将其复制到另一个集合中:

代码语言:javascript
复制
//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对象。

EN

回答 1

Stack Overflow用户

发布于 2019-02-11 15:18:15

我终于能解决了。我分享这个问题的答案

代码语言:javascript
复制
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)
  
    });

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54632630

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档