简体   繁体   中英

How to Firebase Firestore realtime update Only new data added to collect?

For example : WorkingTask App. I use Redux - React

Structure

JobOrders (collections) / eachJob (docu)

- the app is allow only insert new JOB.
- the whole day has 500-1000 Jobs.
- the all jobs must be used to recompute the report realtime.  
- clear data once every midnight.

I know how to fetch and listen-realtime callback for the whole. but the problem is the callback function must recompute the whole documents (maybe 300-1000 Jobs every-time when a new JOB arrived.)

This is I want:

- every new JOB arrived only new data in callback then I can recompute in REDUX.  

- and prevent for some data is delay due to internet network connection.

I come across with : to listen limit to 1 and sortBy timestamp 'desc'.

But the problem is if some JOB are delay due to network connection, it will not call in callback.

I'm looking for this problem also but now i find out onAddSnapshotListener // as real time update. only get the new or changed documents

https://youtu.be/3aoxOtMM2rc?t=195

Try to watch the whole series

I think Firestore querySnaptshot should have Information for documents changed

for example Node.js

let observer = db
  .collection('cities')
  .where('state', '==', 'CA')
  .onSnapshot(querySnapshot => {
    querySnapshot.docChanges().forEach(change => {
      if (change.type === 'added') {
        console.log('New city: ', change.doc.data());
      }
      if (change.type === 'modified') {
        console.log('Modified city: ', change.doc.data());
      }
      if (change.type === 'removed') {
        console.log('Removed city: ', change.doc.data());
      }
    });
  });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM