var jobskill_ref = db.collection('job_skills').where('job_id','==',post.job_id);
jobskill_ref.delete();
Error thrown
jobskill_ref.delete is not a function
var jobskill_ref = db.collection('job_skills').where('job_id','==',post.job_id);
jobskill_ref.delete();
Error thrown
jobskill_ref.delete is not a function
the key part of Frank's answer that fixed my issues was the
.ref
indoc.ref.delete()
I originally only had
doc.delete()
which gave a "not a function" error. now my code looks like this and works perfectly:And of course, you can use await/async:
I have no idea why you have to get() them and loop on them, then delete() them, while you can prepare one query with where to delete in one step like any SQL statement, but Google decided to do it like that. so, for now, this is the only option.
You can only delete a document once you have a
DocumentReference
to it. To get that you must first execute the query, then loop over theQuerySnapshot
and finally delete eachDocumentSnapshot
based on itsref
.I use batched writes for this. For example:
ES6 async/await: