My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

How do I delete a photo in Firestore from a nested photos collection?

Vijay Thirugnanam's photo
Vijay Thirugnanam
·Feb 24, 2019

I have a nested collection of photos in my user document.

Screenshot 2019-02-24 at 7.26.05 PM.jpg

The following code works! But, I am wondering if there is an easier way to do it.

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

I like the real-time nature of Firestore and its similarity to Mongo but if I wish that the API was easier :(