I have a firestore. I am trying to delete a specific record from the document 'idAvailable'. However, the id is not deleted from the idAvailable table when we hit this endpoint: http://localhost:5001/us-central1/reserveId which is defined in the below code snippet.
exports.reserveId = functions.https.onRequest(async (req, res) => {
cors(req, res, ()=> {
const documentId = "idAvailable"
const setReserved = "idReserved"
admin.firestore().collection("Vacancy").doc(documentId).get().then(doc => {
const field = doc.data().ar[0]
console.log("Field " + JSON.stringify(field))
// No error but doesn't execute correctly
const doDelete = db.collection("Vacancy").doc(documentId).update(field, admin.firestore.FieldValue.delete())
res.send(doc.data().ar[0])
}).catch(error => {
res.send(error)
})
})
});
Specifically, this line:
const doDelete = db.collection("Vacancy").doc(documentId).update(field, admin.firestore.FieldValue.delete())
does not delete from the collection.
Why is this happening?