如何在FIRESTORE中自动删除空文档(无字段值)

时间:2017-11-16 12:02:31

标签: javascript firebase google-cloud-firestore

我的代码删除了文档中的字段,但是空文档保留在集合中,我想删除文档时它是空的....我是新来的这个plz帮助...谢谢

database

我删除字段的代码

function deletedb(inputx)
{
    firestore.collection("products").where("Product", "==", inputx)
    .get()
    .then(function(querySnapshot) {
        querySnapshot.forEach(function(doc) {
    var databaseRef = firestore.collection("products").doc(doc.id)
    var removeProduct = databaseRef.update({
        Product: firebase.firestore.FieldValue.delete()
    });
    var removePer = databaseRef.update({
        Per: firebase.firestore.FieldValue.delete()
    });
    var removeArea = databaseRef.update({
        Area: firebase.firestore.FieldValue.delete()
    });
    var removeCost = databaseRef.update({
        Cost: firebase.firestore.FieldValue.delete()
    });
    var removeDescription = databaseRef.update({
        Description: firebase.firestore.FieldValue.delete()
    });
});
})
}

0 个答案:

没有答案