node.js - 多个条件匹配时如何删除文档,firestore firebase
问题描述
当多个条件匹配时,我想删除一个 firestore 对象。像下面
db.collection('facilityOwners').where('facilityId', '==', facilityId).where('ownerId', '==', ownerId).delete()
当这两个属性匹配时,我想删除一个文档。而且我不想先找到文档然后执行删除。
解决方案
如果您知道该文档的完整、准确路径,则只能在 Firestore 中写入(并因此删除)该文档。Firestore 不支持等效的 SQLDELETE FROM facilityOwners WHERE ...
查询。
这意味着您首先必须查看get()
查询结果,遍历它们,然后单独或批量删除每个文档。就像是:
let query = db.collection('facilityOwners').where('facilityId', '==', facilityId).where('ownerId', '==', ownerId);
query.get().then((querySnapshot) => {
querySnapshot.forEach((doc) => {
doc.ref.delete();
});
});
另见:
推荐阅读
- url - 如何为具有多个域及其内容的 Gatsby 网站提供服务?
- javascript - 如何获取由css添加的文本的值:javascript中的选择器之后?
- node.js - Firebase NodeJs OrderByChild
- python - Jinja2 在一个
block
- javascript - How to clone and append chose dropedown box using jq?
- ios - I have a custom UIView embed in WKWebview, how to set uiDelegate and navigationDelegate let webview didFinish function work?
- facebook-graph-api - 如何获得工作场所集成权限?
- javascript - Outlook/IE 无法使用 BigInt 数据类型运行插件
- json - 如何在 Swift 中将 JSON 数组保存到 Realm?
- python - 有没有办法从字典中的列表中的特定索引中获取项目(值)