如何使用where子句从firestore中删除文档 [英] How to delete document from firestore using where clause
本文介绍了如何使用where子句从firestore中删除文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
var jobskill_ref = db.collection('job_skills').where('job_id','==',post.job_id);
jobskill_ref.delete();
抛出错误
jobskill_ref.delete不是函数
jobskill_ref.delete is not a function
推荐答案
只有在您拥有 DocumentReference
后才能删除文档。为此,您必须首先执行查询,然后遍历 QuerySnapshot
,最后根据< DocumentSnapshot
code> ref 。
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 the QuerySnapshot
and finally delete each DocumentSnapshot
based on its ref
.
var jobskill_query = db.collection('job_skills').where('job_id','==',post.job_id);
jobskill_query.get().then(function(querySnapshot) {
querySnapshot.forEach(function(doc) {
doc.ref.delete();
});
});
这篇关于如何使用where子句从firestore中删除文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文