How to get all the data underneath a document based on a ID

currently i’m learning Firestore and struggling to write a query. I want to target all the fields under the giMXcFmLUxfCaCmyYo0TJFeEHBL2 document. My query is looking like this:

 if (userId) {
  firebase
    .firestore()
    .collection('userLists')
    .doc(userId)
    .get()
    .then(docRef => {
      console.log('DATA', docRef.data());
    })
    .catch(error => {
      console.log('Nothing here');
    });
 }

docRef.data() is keep saying it is undefined.. what am i doing wrong (sorry for maybe dumb question..).
My goal is to get all the objects e.g.

2gzrNnVjpKOGLz2lxT6n
  id: "2gzrNnVjpKOGLz2lxT6n"
  time: 31 January 2021 at 00:00:00 UTC+1

Security Rules:

    rules_version = '2';
      service cloud.firestore {
        match /databases/{database}/documents {
          match /{document=**} {
            allow read, write: if false;
          }
    
          match /lists/{document=**} {
            allow read, write: if true;
          }
    
          match /users/{document=**} {
            allow read, write: if true;
          }
    
          match /userLists/{document=**} {
            allow read, write: if true;
          }
       }
    }

Leave a Comment