title: Firebase onSnapshot, how to only get "NEW" data with "added" type | React.js
body: <p>I have this application where i only want to get the data that is added to my firestore database using onSnapshot function to get realtime results, the problem is that, it doesn't only give me that data, but the whole collection that is already there, and i don't care about data that is already stored, i just want the new docs !!</p>
  <p>Let me show what i've done</p>
  <p>This is my config</p>
  <pre><code>import { getFirestore } from '@firebase/firestore';
  import { initializeApp } from 'firebase/app';
  
  const firebaseConfig = {
      apiKey: process.env.REACT_APP_RECOGIDAS_API_KEY,
      authDomain: process.env.REACT_APP_RECOGIDAS_AUTH_DOMAIN,
      appId: process.env.REACT_APP_RECOGIDAS_APP_ID,
      databaseURL: process.env.REACT_APP_RECOGIDAS_DATABAS_EURL,
      measurementId: process.env.REACT_APP_RECOGIDAS_MEASUREMENT_ID,
      messagingSenderId: process.env.REACT_APP_RECOGIDAS_MESSAGING_SENDER_ID,
      projectId: process.env.REACT_APP_RECOGIDAS_PROJECT_ID,
      storageBucket: process.env.REACT_APP_RECOGIDAS_STORAGE_BUCKET,
  };
  
  export const recogidas = initializeApp(firebaseConfig);
  
  export const recogidas_db = getFirestore(recogidas);
  </code></pre>
  <p>This is a query that i'm using to filter result</p>
  <pre><code>import { collection, query, where } from '@firebase/firestore';
  
  import { recogidas_db } from '../adapter/recogidasConfig';
  
  export const config = (terminal: number) =&gt;
      query(collection(recogidas_db, 'solicitudes_sin_asignar'), where('codigo_terminal', '==', terminal));
  
  </code></pre>
  <p>And this is the actual onSnapshot</p>
  <pre><code> useEffect(() =&gt; {
          const unsubscribe = onSnapshot(
              config(terminal!),
              (snapshot) =&gt; {
                  let addedData: any[] = [];
                  let deletedData: any[] = [];
  
                  snapshot.docChanges().forEach((change) =&gt; {
                      if (change.type === 'removed') {
                          console.log(change.doc.data());
                          deletedData = [...deletedData, change.doc.data()];
                      }
                      if (change.type === 'added') {
            
  
                          console.log(change.doc.data());
  
                          addedData = [...addedData, change.doc.data()];
  
                      }
                  });
  
                 
              },
          );
  
          return () =&gt; unsubscribe();
  
      }, [terminal]);
  </code></pre>
  <p>Now, as i said before <code>change.type === 'added'</code> is returning not only new docs, but stuff that is already there, but i don't want that, i just want new docs, can i accomplish that ? is it possible ? How can i do it?</p>