Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to delete a field with a dynamic name from Firestore

I can’t delete this field from firestore:

any suggestions?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I have firebaseConfig, it’s just big so i didn’t paste it here.

const app = initializeApp(firebaseConfig);
const db = getFirestore(app);

I tried to use code below but vsStudio’s showing ‘Signature declarations can only be used in TypeScript files’

updateDoc(doc(db, "userChats", currentUser.uid),{
  deleteField(fieldId)
})

>Solution :

The syntax to delete a field is:

updateDoc(referenceToDocument,{
  "fieldName": deleteField()
})

If you want to use a variable as the field name, that’d be:

updateDoc(referenceToDocument,{
  [fieldNameVariable]: deleteField()
})
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading