Himansa Eshan
Himansa Eshan

Reputation: 335

How to get array from firebase firestore

I'm doing a react project for download movies . In this project user can like to movie and add to watchlist. I need to get array of like and store it on browser local storage . I need to know how to get array from firestore .


This is path of array I need to get.

users > {user id} > likes



This is what I tried.

firebase
   .firestore()
   .collection("users")
   .doc(firebase.auth().currentUser.uid)
   .collection("likes")
   .get()
   .then((likes) => {
       console.log(likes)
             });

This is my data structure

Upvotes: 0

Views: 213

Answers (2)

Alpay GÜNEŞ
Alpay GÜNEŞ

Reputation: 29

Try like this

         firebase
   .firestore()
   .collection("users")
   .doc(firebase.auth().currentUser.uid)
   .get()
   .then((user_doc) => {
       console.log(user_doc.data())
    });

Upvotes: 1

Arup
Arup

Reputation: 131

.collection("likes") likes is a field not a collection so to get likes field you have to read whole document.

Upvotes: 1

Related Questions