如何从Firestore中的文档中的数组中删除项目?

时间:2019-02-24 15:11:41

标签: google-cloud-firestore

我在用户文档中有一个照片阵列。 enter image description here

我正在尝试通过URL删除照片。我写了下面的代码,它可以工作。有没有我不知道的更简单的API?谢谢。

const userDoc = await firestore
    .collection('users')
    .doc(user.uid)
    .get();
const userDocPhoto = userDoc.data().photos.find(p => p.url === url);
await firestore
    .collection('users')
    .doc(user.uid)
    .update({
        photos: firebase.firestore.FieldValue.arrayRemove(userDocPhoto)
    });

0 个答案:

没有答案
相关问题