Home > Enterprise >  FirebaseError: Expected type 'Hc', but it was: a custom Yc object]
FirebaseError: Expected type 'Hc', but it was: a custom Yc object]

Time:11-25

i am trying to do a batch entry, but this error keeps occurring. i am passing an array in a .doc, it works fine on other function, where i pass an array into .doc using loops and functions.

please help me out and please explain me what the error means.

export const AddTaskToFriend = (
  ArryOfIds,
  email,
  title,
  tag,
  prayority,
  completed
) => {
  return async (dispatch) => {
    const db = firebase.firestore();
    var batch = db.batch();

    for (let i = 0; i < ArryOfIds.length; i  ) {
      const Collections = db
        .collection("Tasks")
        .doc(ArryOfIds[i])
        .collection("SingleTask");
      batch.set(Collections, {
        creater: firebase.auth().currentUser.uid,
        UpdatedOn: new Date().toString(),
        CreatedOn: new Date().toString(),
        email,
        title,
        tag,
        prayority,
        completed,
      });
    }
    batch
      .commit()
      .then((success) => {
        console.log(` its a success ${success}`);
      })
      .catch((error) => {
        console.log(error);
      });

CodePudding user response:

It looks like the error could come from batch.set(). As per this documentation .set() needs a reference to a document, and in your case you are passing a collection reference:

const Collections = db
        .collection("Tasks")
        .doc(ArryOfIds[i])
        .collection("SingleTask");

You could try adding .doc() after .collection("SingleTask") to see if this solves the issue.

  • Related