title: How to get all documents in a collection from Firestore in React Native
body: <p>I am trying to retrieve all documents from the 'users' collection in my firestore DB:</p>
  <p><a href="https://i.stack.imgur.com/lRBZy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lRBZy.png" alt="enter image description here" /></a></p>
  <p>For now I'd just like to retrieve each <code>userName</code> and <code>Role</code>. I have seen a lost of similar questions but they always use snapshots like this:</p>
  <pre><code>async getMarkers() {
    const events = await firebase.firestore().collection('events').get()
      .then(querySnapshot =&gt; {
        querySnapshot.docs.map(doc =&gt; {
          console.log('LOG 1', doc.data());
          return doc.data();
        });
      });
    console.log('LOG 2', events);
    return events;
  }
  </code></pre>
  <p>But I think my project structure is a bit different.</p>
  <p>Here is my index.js located in the firebase folder:</p>
  <h2>Index.js</h2>
  <pre><code>import * as firebase from 'firebase';
  import 'firebase/firestore';
  
  const firebaseConfig = {
      apiKey: &quot;AIzaSyDVyMU4XZEaLmT17ksu2S6ndnypNwL555s&quot;,
      authDomain: &quot;cyberpunkprojv1.firebaseapp.com&quot;,
      databaseURL: &quot;https://cyberpunkprojv1.firebaseio.com&quot;,
      projectId: &quot;cyberpunkprojv1&quot;,
      storageBucket: &quot;cyberpunkprojv1.appspot.com&quot;,
      messagingSenderId: &quot;837539155372&quot;,
      appId: &quot;1:837539155372:web:e52a4bd30fd0c9da29be09&quot;,
      measurementId: &quot;G-JGRZT5YX0Q&quot;
  };
  
  export const init = () =&gt; {
      return firebase.initializeApp(firebaseConfig);
  }
  
  
  export const createUser = (user) =&gt;
      firebase.firestore().collection('users').doc(user.userName).set(user); // I need to know how to create a subcollection when creating a document
  
  
  export const getAllUsers = () =&gt; firebase.firestore().collection('users').get(); //This line does not work right now.
  
  </code></pre>
  <p>What I am primarily concerned with here is <code> getAllUsers</code>. Note though that <code>createUser</code> works exactly as intended.</p>
  <p>This is in another .js screen in which <code>getAllUsers</code> is called:</p>
  <h2>CharacterViewScreen.js</h2>
  <pre><code>   React.useEffect(()=&gt;{
          console.log('Select Screen loaded.')
          userFetch();
        },[])
  
      const userFetch = async () =&gt; {
          try{
              await firebase.init();
      
              const users = await firebase.getAllUsers();
              console.log(users);
      
          } catch (error) {
              console.log(error);
          }
      }
  </code></pre>
  <p>The function runs correctly however this is what is logged in the console:</p>
  <h2>Console</h2>
  <pre><code>Select Screen loaded.
  t {
    &quot;SP&quot;: null,
    &quot;gP&quot;: t {
      &quot;Je&quot;: Array [],
      &quot;Ze&quot;: &quot;F&quot;,
      &quot;collectionGroup&quot;: null,
      &quot;en&quot;: t {
        &quot;Ye&quot;: &quot;users|f:|ob:__name__asc,&quot;,
        &quot;collectionGroup&quot;: null,
        &quot;endAt&quot;: null,
        &quot;filters&quot;: Array [],
        &quot;limit&quot;: null,
        &quot;orderBy&quot;: Array [
          t {
            &quot;dir&quot;: t {
              &quot;name&quot;: &quot;asc&quot;,
            },
            &quot;field&quot;: e {
              &quot;len&quot;: 1,
              &quot;offset&quot;: 0,
              &quot;segments&quot;: Array [
                &quot;__name__&quot;,
              ],
            },
            &quot;wn&quot;: true,
          },
        ],
        &quot;path&quot;: e {
          &quot;len&quot;: 1,
          &quot;offset&quot;: 0,
          &quot;segments&quot;: Array [
            &quot;users&quot;,
          ],
        },
        &quot;startAt&quot;: null,
      },
      &quot;endAt&quot;: null,
      &quot;filters&quot;: Array [],
      &quot;limit&quot;: null,
      &quot;path&quot;: e {
        &quot;len&quot;: 1,
        &quot;offset&quot;: 0,
        &quot;segments&quot;: Array [
          &quot;users&quot;,
        ],
      },
      &quot;startAt&quot;: null,
      &quot;tn&quot;: Array [
        t {
          &quot;dir&quot;: t {
            &quot;name&quot;: &quot;asc&quot;,
          },
          &quot;field&quot;: e {
            &quot;len&quot;: 1,
            &quot;offset&quot;: 0,
            &quot;segments&quot;: Array [
              &quot;__name__&quot;,
            ],
          },
          &quot;wn&quot;: true,
        },
      ],
    },
    &quot;iP&quot;: undefined,
    &quot;metadata&quot;: t {
      &quot;fromCache&quot;: false,
      &quot;hasPendingWrites&quot;: false,
    },
    &quot;nP&quot;: t {
      &quot;$E&quot;: t {
        &quot;tl&quot;: [Function anonymous],
      },
      &quot;BE&quot;: FirebaseAppImpl {
        &quot;automaticDataCollectionEnabled_&quot;: false,
        &quot;container&quot;: ComponentContainer {
          &quot;name&quot;: &quot;[DEFAULT]&quot;,
          &quot;providers&quot;: Map {
            &quot;app&quot; =&gt; Provider {
              &quot;component&quot;: Component {
                &quot;instanceFactory&quot;: [Function anonymous],
                &quot;instantiationMode&quot;: &quot;LAZY&quot;,
                &quot;multipleInstances&quot;: false,
                &quot;name&quot;: &quot;app&quot;,
                &quot;serviceProps&quot;: Object {},
                &quot;type&quot;: &quot;PUBLIC&quot;,
              },
              &quot;container&quot;: [Circular],
              &quot;instances&quot;: Map {
                &quot;[DEFAULT]&quot; =&gt; [Circular],
              },
              &quot;instancesDeferred&quot;: Map {},
              &quot;name&quot;: &quot;app&quot;,
            },
            &quot;platform-logger&quot; =&gt; Provider {
              &quot;component&quot;: Component {
                &quot;instanceFactory&quot;: [Function anonymous],
                &quot;instantiationMode&quot;: &quot;LAZY&quot;,
                &quot;multipleInstances&quot;: false,
                &quot;name&quot;: &quot;platform-logger&quot;,
                &quot;serviceProps&quot;: Object {},
                &quot;type&quot;: &quot;PRIVATE&quot;,
              },
              &quot;container&quot;: [Circular],
              &quot;instances&quot;: Map {},
              &quot;instancesDeferred&quot;: Map {},
              &quot;name&quot;: &quot;platform-logger&quot;,
            },
            &quot;fire-core-rn-version&quot; =&gt; Provider {
              &quot;component&quot;: Component {
                &quot;instanceFactory&quot;: [Function anonymous],
                &quot;instantiationMode&quot;: &quot;LAZY&quot;,
                &quot;multipleInstances&quot;: false,
                &quot;name&quot;: &quot;fire-core-rn-version&quot;,
                &quot;serviceProps&quot;: Object {},
                &quot;type&quot;: &quot;VERSION&quot;,
              },
              &quot;container&quot;: [Circular],
              &quot;instances&quot;: Map {},
              &quot;instancesDeferred&quot;: Map {},
              &quot;name&quot;: &quot;fire-core-rn-version&quot;,
            },
            &quot;fire-js-version&quot; =&gt; Provider {
              &quot;component&quot;: Component {
                &quot;instanceFactory&quot;: [Function anonymous],
                &quot;instantiationMode&quot;: &quot;LAZY&quot;,
                &quot;multipleInstances&quot;: false,
                &quot;name&quot;: &quot;fire-js-version&quot;,
                &quot;serviceProps&quot;: Object {},
                &quot;type&quot;: &quot;VERSION&quot;,
              },
              &quot;container&quot;: [Circular],
              &quot;instances&quot;: Map {},
              &quot;instancesDeferred&quot;: Map {},
              &quot;name&quot;: &quot;fire-js-version&quot;,
            },
            &quot;auth&quot; =&gt; Provider {
              &quot;component&quot;: Object {
                &quot;instanceFactory&quot;: [Function instanceFactory],
                &quot;instantiationMode&quot;: &quot;LAZY&quot;,
                &quot;multipleInstances&quot;: false,
                &quot;name&quot;: &quot;auth&quot;,
                &quot;serviceProps&quot;: Object {
                  &quot;ActionCodeInfo&quot;: Object {
                    &quot;Operation&quot;: Object {
                      &quot;EMAIL_SIGNIN&quot;: &quot;EMAIL_SIGNIN&quot;,
                      &quot;PASSWORD_RESET&quot;: &quot;PASSWORD_RESET&quot;,
                      &quot;RECOVER_EMAIL&quot;: &quot;RECOVER_EMAIL&quot;,
                      &quot;VERIFY_EMAIL&quot;: &quot;VERIFY_EMAIL&quot;,
                    },
                  },
                  &quot;ActionCodeURL&quot;: [Function d],
                  &quot;Auth&quot;: [Function Lm],
                  &quot;AuthCredential&quot;: [Function kg],
                  &quot;EmailAuthProvider&quot;: [Function d],
                  &quot;Error&quot;: [Function M],
                  &quot;FacebookAuthProvider&quot;: [Function d],
                  &quot;GithubAuthProvider&quot;: [Function d],
                  &quot;GoogleAuthProvider&quot;: [Function d],
                  &quot;OAuthProvider&quot;: [Function d],
                  &quot;PhoneAuthProvider&quot;: [Function d],
                  &quot;RecaptchaVerifier&quot;: [Function d],
                  &quot;SAMLAuthProvider&quot;: [Function d],
                  &quot;TwitterAuthProvider&quot;: [Function d],
                },
                &quot;type&quot;: &quot;PUBLIC&quot;,
              },
              &quot;container&quot;: [Circular],
              &quot;instances&quot;: Map {
                &quot;[DEFAULT]&quot; =&gt; Object {
                  &quot;apiKey&quot;: &quot;AIzaSyDVyMU4XZEaLmT17ksu2S6ndnypNwL555s&quot;,
                  &quot;appName&quot;: &quot;[DEFAULT]&quot;,
                  &quot;authDomain&quot;: &quot;cyberpunkprojv1.firebaseapp.com&quot;,
                  &quot;currentUser&quot;: null,
                },
              },
              &quot;instancesDeferred&quot;: Map {},
              &quot;name&quot;: &quot;auth&quot;,
            },
            &quot;auth-internal&quot; =&gt; Provider {
              &quot;component&quot;: Object {
                &quot;instanceFactory&quot;: [Function instanceFactory],
                &quot;instantiationMode&quot;: &quot;LAZY&quot;,
                &quot;multipleInstances&quot;: false,
                &quot;name&quot;: &quot;auth-internal&quot;,
                &quot;type&quot;: &quot;PRIVATE&quot;,
              },
              &quot;container&quot;: [Circular],
              &quot;instances&quot;: Map {
                &quot;[DEFAULT]&quot; =&gt; Object {
                  &quot;addAuthTokenListener&quot;: [Function bound ],
                  &quot;getToken&quot;: [Function bound ],
                  &quot;getUid&quot;: [Function bound ],
                  &quot;removeAuthTokenListener&quot;: [Function bound ],
                },
              },
              &quot;instancesDeferred&quot;: Map {},
              &quot;name&quot;: &quot;auth-internal&quot;,
            },
            &quot;fire-auth-version&quot; =&gt; Provider {
              &quot;component&quot;: Component {
                &quot;instanceFactory&quot;: [Function anonymous],
                &quot;instantiationMode&quot;: &quot;LAZY&quot;,
                &quot;multipleInstances&quot;: false,
                &quot;name&quot;: &quot;fire-auth-version&quot;,
                &quot;serviceProps&quot;: Object {},
                &quot;type&quot;: &quot;VERSION&quot;,
              },
              &quot;container&quot;: [Circular],
              &quot;instances&quot;: Map {},
              &quot;instancesDeferred&quot;: Map {},
              &quot;name&quot;: &quot;fire-auth-version&quot;,
            },
            &quot;database&quot; =&gt; Provider {
              &quot;component&quot;: Component {
                &quot;instanceFactory&quot;: [Function anonymous],
                &quot;instantiationMode&quot;: &quot;LAZY&quot;,
                &quot;multipleInstances&quot;: true,
                &quot;name&quot;: &quot;database&quot;,
                &quot;serviceProps&quot;: Object {
                  &quot;DataSnapshot&quot;: [Function DataSnapshot],
                  &quot;Database&quot;: [Function Database],
                  &quot;INTERNAL&quot;: Object {
                    &quot;dataUpdateCount&quot;: [Function dataUpdateCount],
                    &quot;forceLongPolling&quot;: [Function forceLongPolling],
                    &quot;forceWebSockets&quot;: [Function forceWebSockets],
                    &quot;interceptServerData&quot;: [Function interceptServerData],
                    &quot;isWebSocketsAvailable&quot;: [Function isWebSocketsAvailable],
                    &quot;setSecurityDebugCallback&quot;: [Function setSecurityDebugCallback],
                    &quot;stats&quot;: [Function stats],
                    &quot;statsIncrementCounter&quot;: [Function statsIncrementCounter],
                  },
                  &quot;Query&quot;: [Function Query],
                  &quot;Reference&quot;: [Function Reference],
                  &quot;ServerValue&quot;: Object {
                    &quot;TIMESTAMP&quot;: Object {
                      &quot;.sv&quot;: &quot;timestamp&quot;,
                    },
                  },
                  &quot;TEST_ACCESS&quot;: Object {
                    &quot;ConnectionTarget&quot;: [Function RepoInfo],
                    &quot;DataConnection&quot;: [Function PersistentConnection],
                    &quot;RealTimeConnection&quot;: [Function Connection],
                    &quot;forceRestClient&quot;: [Function forceRestClient],
                    &quot;hijackHash&quot;: [Function hijackHash],
                    &quot;queryIdentifier&quot;: [Function queryIdentifier],
                  },
                  &quot;enableLogging&quot;: [Function enableLogging],
                },
                &quot;type&quot;: &quot;PUBLIC&quot;,
              },
              &quot;container&quot;: [Circular],
              &quot;instances&quot;: Map {},
              &quot;instancesDeferred&quot;: Map {},
              &quot;name&quot;: &quot;database&quot;,
            },
            &quot;fire-rtdb-version&quot; =&gt; Provider {
              &quot;component&quot;: Component {
                &quot;instanceFactory&quot;: [Function anonymous],
                &quot;instantiationMode&quot;: &quot;LAZY&quot;,
                &quot;multipleInstances&quot;: false,
                &quot;name&quot;: &quot;fire-rtdb-version&quot;,
                &quot;serviceProps&quot;: Object {},
                &quot;type&quot;: &quot;VERSION&quot;,
              },
              &quot;container&quot;: [Circular],
              &quot;instances&quot;: Map {},
              &quot;instancesDeferred&quot;: Map {},
              &quot;name&quot;: &quot;fire-rtdb-version&quot;,
            },
            &quot;storage&quot; =&gt; Provider {
              &quot;component&quot;: Component {
                &quot;instanceFactory&quot;: [Function factory],
                &quot;instantiationMode&quot;: &quot;LAZY&quot;,
                &quot;multipleInstances&quot;: true,
                &quot;name&quot;: &quot;storage&quot;,
              &quot;container&quot;: [Circular],
              &quot;instances&quot;: Map {},
              &quot;instancesDeferred&quot;: Map {},
              &quot;name&quot;: &quot;fire-rtdb-version&quot;,
            },
            &quot;storage&quot; =&gt; Provider {
              &quot;component&quot;: Component {
                &quot;instanceFactory&quot;: [Function factory],
                &quot;instantiationMode&quot;: &quot;LAZY&quot;,
                &quot;multipleInstances&quot;: true,
                &quot;name&quot;: &quot;storage&quot;,
                &quot;serviceProps&quot;: Object {
                  &quot;Reference&quot;: [Function Reference],
                  &quot;Storage&quot;: [Function Service],
                  &quot;StringFormat&quot;: Object {
                    &quot;BASE64&quot;: &quot;base64&quot;,
                    &quot;BASE64URL&quot;: &quot;base64url&quot;,
                    &quot;DATA_URL&quot;: &quot;data_url&quot;,
                    &quot;RAW&quot;: &quot;raw&quot;,
                  },
                  &quot;TaskEvent&quot;: Object {
                    &quot;STATE_CHANGED&quot;: &quot;state_changed&quot;,
                  &quot;TaskState&quot;: Object {
                    &quot;CANCELED&quot;: &quot;canceled&quot;,
                    &quot;ERROR&quot;: &quot;error&quot;,
                    &quot;PAUSED&quot;: &quot;paused&quot;,
                    &quot;RUNNING&quot;: &quot;running&quot;,
                    &quot;SUCCESS&quot;: &quot;s...(truncated to the first 10000 characters)
  </code></pre>
  <p>I feel like I have to be pretty close but I have no ides what that users object that is being logged actually is. Can I actually do this using this approach or do I have to use the snapshots like in the example? My method at least works a little bit because I created all of those database entries useing the <code>createUser</code> method in Index.js that is called a similar way in another view.</p>
  <p>If I need to add any additional information please let me know.</p>