Reputation: 191
for some reason it is throwing me an error in the console "TypeError: n.indexOf is not a function" and I do not understand very well why it happens. I am using Firestore and Firebase v9 Modular and basically it is a function that creates a category in firestore database and also inside the category creates a test task.
Here is the full error:
TypeError: n.indexOf is not a function
at Function.fromString (index.esm2017.js:1032)
at va (index.esm2017.js:14990)
at App.jsx:48
And the line 48 in the error message is:
const taskRef = doc(collection(db, "categorias"), where("uid", "==", currentUser), newDocRef.id)
Here is my code :)
const currentUser = '1234'
const crearCategoria = useCallback(async() => {
try {
const newDocRef = doc(collection(db, "categorias"));
await setDoc(newDocRef, {
name: categoryName,
uid: currentUser,
projectId: newDocRef.id
})
const taskRef = doc(collection(db, "categorias"), where("uid", "==", currentUser), newDocRef.id)
await setDoc(taskRef, {
name: 'prueba',
uid: currentUser,
projectId: newDocRef.id
})
} catch (error) {
console.log(error)
}
})
Upvotes: 6
Views: 7997
Reputation: 598728
As Dharmaraj commented, you cannot perform an update on a query. You'll instead have to:
In code that should be something like:
const taskQuery = doc(collection(db, "categorias"), where("uid", "==", currentUser))
const taskDocs = await getDocs(taskQuery)
taskDocs.forEach((taskDoc) => {
await setDoc(taskDoc.ref, {
name: 'prueba',
uid: currentUser,
projectId: newDocRef.id
})
})
Upvotes: 4