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

347
Views
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 answers
Answer question

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 Report
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!