【发布时间】:2019-03-18 08:24:48
【问题描述】:
我想编写一个脚本,从状态 == 过期的子集合的所有文档中删除数据。 我有集合名称 user_data 并且此集合包含许多文档所有文档都包含子集合名称 My_status 并且此 My_status 包含许多文档,每个文档都包含状态并且如果状态 === 过期而不是删除该数据
数据库结构是这样的
collection - user_data
document1 - Subcollection - My_status --document1- Status expire
document2
document3
document2 - Subcollection - My_status --document1
document2--Status expire
document3
我已经尝试过了,但这不起作用,因为我无法将其与子集合相关联
// First perform the query
db.collection('user_data').where('status','==',expire).get()
.then(function(querySnapshot) {
// Once we get the results, begin a batch
var batch = db.batch();
querySnapshot.forEach(function(doc) {
// For each doc, add a delete operation to the batch
batch.delete(doc.ref);
});
// Commit the batch
return.batch.commit();
}).then(function() {
// Delete completed!
// ...
});
【问题讨论】:
标签: node.js database firebase google-cloud-firestore