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

348
Visualizações
Firebase Error: TypeError: Cannot use 'in' operator to search for '_delegate' in undefined

I'm new to firebase and have been having some difficulties over the past two days with querying and deleting documents from a collection. Specifically, I am trying to clear my entire collection of company dummy data each time I start the server before I loop over the dummy data and write it to the collection (to prevent duplication).

I have been able to take my company dummy data and write it to my 'companies' collection no problem. The problem is when I attempt to delete a doc from the collection; it does not delete and appears to throw the following error when passing the retrieve variable to the deleteDoc() method.

Note: I decided to try deleting just one doc first. If I can do that successfully and it is reflected in the firebase collection, then I should be able to clear the whole collection with no problem.

TypeError: Cannot use 'in' operator to search for '_delegate' in undefined

I understand that the 'in' keyword is only valid when checking if a property exists on an object. I logged the data at each point of the function to make sure I was referencing the doc correctly and passing the appropriate data type to the deleteDoc() function (which would be an object).

Here is my code for writing the dummy data to the database (works fine):

export const dummyDataToFirebase = async() => {
  try {
    const batch = writeBatch(db);
    dummyData.forEach(doc => {
      addDoc(companyRef, doc)
      console.log(doc)
    })
    await batch.commit();
    console.log('success!')

  } catch (error) {
    console.error(error, 'try again!');
  }
} 

Here is my code for deleting a doc from the database collection (problem)

const deleteOne = async () => {
  try {
    const docRef = doc(companyRef, '86e9cade14e2a972c526db4b7c828ed7')
    const retrieve = await getDoc(docRef)
    console.log(retrieve)
    await deleteDoc(retrieve)
    if(retrieve.exists()) {
      console.log('still exists')
    } else {
      console.log('it worked!')
    }
  } catch (error) {
    console.error(error, 'nope')
  }
}
deleteOne()

Here is the error I get from the deleteDoc function I wrote:

index.js:1 TypeError: Cannot use 'in' operator to search for '_delegate' in undefined at Tc (index.esm2017.js:14691) at ph (index.esm2017.js:17522) at deleteOne (Firebase.jsx:101) 'nope'[enter image description here][1]

retrieve object that is console.logged [1]: https://i.stack.imgur.com/srxpq.png error in console [2]: https://i.stack.imgur.com/p2xQk.png

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

deleteDoc needs a DocumentReference. What you are passing is the DocumentSnapshot. If you use deleteDoc(docRef), you shouldn't get this error.

about 4 years ago · Juan Pablo Isaza Relatório
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