如何使用UUID从集合中删除项目?

时间:2019-08-13 21:56:19

标签: reactjs google-cloud-firestore

我有一个简单的firestore集合,我希望能够使用创建项目时生成的UUID删除项目。我该怎么办?

我的物品看起来像这样

{ id: UUID,
  name: name,
  itemLocation: xyz,
  itemQuant: 1000
}

1 个答案:

答案 0 :(得分:0)

由于可能有多个文档的UUID字段具有相同的值,因此您需要run a query to find those documents,然后将结果循环到delete每个文档中。

类似的东西:

db.collection("yourcollection").where("id", "==", "valueOfUUIDYouWantToDelete")
    .get()
    .then(function(querySnapshot) {
        querySnapshot.forEach(function(doc) {
            doc.ref.delete()
        });
    })
    .catch(function(error) {
        console.log("Error querying documents to delete: ", error);
    });
相关问题