Uncaught (in promise) FirebaseError: Expected type 'rc', but it was: a custom ac object

Uncaught (in promise) FirebaseError: Expected type 'rc', but it was: a custom ac object

错误发生在这段代码中:

document.querySelector('.adding').onclick = async function adding() {

  const output = document.querySelector('.added')
  const translate = collection(db, "translate")
  await setDoc(translate, {
    eng_tot,
    sank_tot
  });
  output.innerText = 'Added'
  console.log('added', english, sanskrit)
  english.value = ''
  sanskrit.value = ''
  eng_tot = []
  sank_tot = []
  setTimeout(() => {
    output.innerText = ''
  }, 2000);
};

** 我尝试了 2 天,但无法理解问题所在!!**

我正在尝试在 firebase 中添加一个数组,我尝试了很多解决方案但无法解决问题!!

setDoc() function takes a DocumentReference as first parameter but you are passing a CollectionReference. If you want to add a document with random ID then use addDoc()改为:

import { collection, addDoc } from "firebase/firestore"

const translate = collection(db, "translate")
await addDoc(translate, {
  eng_tot,
  sank_tot
});

如果您想自己指定文档 ID,请使用 doc() 创建文档引用,然后使用 setDoc():

import { doc, setDoc } from "firebase/firestore"

const translateDoc = doc(db, "translate", "custom_doc_id")
await setDoc(translateDoc, {
  eng_tot,
  sank_tot
});