Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

224
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!