DocumentReference.update() 在尝试替换旧数组时使用无效数据调用

DocumentReference.update() called with invalid data when trying to replace old array

我创建了一个对象,这个对象里面有一个数组(数组对象),像这样: .

但在其他情况下,我需要在此数组对象中添加嵌套数组。假设我想在 chapters 索引号 0 中插入新字段。我希望它变成这样:

-chapters
 - 0 : -chapter: 'Pendahuluan'
       -chapterDesc: 'bla.. bla'
       -id: 59291
       -materi: 
         -0 : title: 'bla..bla'
              desc: 'desc bla.. bla'
         -1 : title: 'bla.. bla again'
            : desc: 'desc bla.. bla.. again'

我这样做了;

const handleMateri = async (data, index) => {
      showModal.value = false

      const allOldChapter = course.value.chapters
      console.log('old',allOldChapter)

      const newAllChapter = allOldChapter.map(chap => chap.id !== data.id ? chap : data)

      console.log('new',newAllChapter)

      await updateDoc('courses', props.id, { chapters:  newAllChapter})

    }

Firestore更新功能

const updateDoc = async(collection, id, updates) => {
        isPending.value = true
        error.value = null

        try{
            let docRef = projectFirestore.collection(collection).doc(id)
            const res = await docRef.update(updates)
            isPending.value = false
            return res

        }catch(err){
            isPending.value = false
            error.value = err.message
            console.log(err.message)

        }

    }

然后我遇到了这个问题

有人可以帮助我吗?

错误消息告诉您在写入 Firestore 时不能使用自定义对象。据我从您的输出中可以看出,您的自定义对象称为“代理”。你将无法使用它。相反,您必须将其转换为 Firestore 允许的内容,例如基本 JavaScript 对象、数组和其他基本类型。