最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Firebase Error: TypeError: Cannot use 'in' operator to search for '_delegate' in un

programmeradmin3浏览0评论

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 pany 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 pany dummy data and write it to my 'panies' 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(panyRef, doc)
      console.log(doc)
    })
    await batchmit();
    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(panyRef, '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

error in console

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 pany 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 pany dummy data and write it to my 'panies' 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(panyRef, doc)
      console.log(doc)
    })
    await batch.mit();
    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(panyRef, '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

error in console

Share Improve this question edited Jan 9, 2023 at 7:37 Dan Bonachea 2,4975 gold badges18 silver badges34 bronze badges asked Dec 15, 2021 at 14:59 jasonghentjasonghent 1011 gold badge1 silver badge4 bronze badges 1
  • ~I'm getting this error as well. Looks like a bug.~ nvm I had the ref as undefined. – Abdulsattar Mohammed Commented Jan 6, 2022 at 9:13
Add a ment  | 

1 Answer 1

Reset to default 5

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

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论