Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

228
Visualizações
How can I update the "Important" field, which is stored in a subcollection?

How can I update the "Important" field, which is stored in a subcollection?

See image to understand better

import firebaseApp from "../../utils/firebase";
import { getFirestore, doc, updateDoc } from "firebase/firestore";
const firestoreDB = getFirestore(firebaseApp);
const USER_DATA = "UsersData";
const TASKS = "Tasks";

const updateImportantValue = async (userID, newValue) => {
  try {
    const docRef = doc(
      firestoreDB,
      USER_DATA,
      userID,
      TASKS,
      "EyS9R8dHV3EU3WS2PeQo"
    );

    await updateDoc(docRef, {
      important: newValue,
    });

    console.log(firestoreDB);
    console.log(USER_DATA);
    console.log(userID);
    console.log(TASKS);
    console.log(newValue);

    console.log("updateImportantValue - success");
  } catch (error) {
    console.log(error);
  }
};

I tried this way but it throws me an error:

TypeError: n.indexOf is not a function

at Function.fromString (index.esm2017.js:1084:1)
at ia (index.esm2017.js:16166:1)
at updateImportantValue (updateImportantValue.js:9:1)
at removeImportant (useTask.js:76:1)
at importantButton (TaskData.js:16:1)
at onClick (TaskData.js:37:1)
at HTMLUnknownElement.callCallback (react-dom.development.js:3945:1)
at Object.invokeGuardedCallbackDev (react-dom.development.js:3994:1)
at invokeGuardedCallback (react-dom.development.js:4056:1)
at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:4070:1)

Update

Update, I was not receiving the User ID correctly. I corrected the error and the console indicates that everything was correct, but in firestore the document does not undergo any change, the "important" field remains the same.

console.log

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda