0

Assume that I have a collection named "students" below:

  • collection students has 3 fields:
    • name
    • age
    • status (0: passed, 1: failed, -1: not tested)

('status' field describles the student passed or failed or Notyet tested)

  • The collection students has 1000 documents with different 'status'
  • Now I want to get the count of students who [passed/failed/not tested] the exam
  • And whenever 'status' of a student is updated 0/1/-1 then I will have to re-count.

How can I solve this? I shouldn't query all data for everytime update because it will cause high cost. NOTICE that, I want to count base on the 'status' field.

Bean
  • 23
  • 6
  • Please check the duplicate to see how you can solve but instead of a CollectionReference simply use a Query. – Alex Mamo Aug 06 '20 at 11:51
  • Actually the duplicated you mentioned is just related to when I add or delete a document. My question is different: assume I have 1000 documents (and I will NOT add/delete any document),I want to count the students with different 'status' fields – Bean Sep 15 '20 at 16:34
  • That's the exact same approach. – Alex Mamo Sep 15 '20 at 16:44

0 Answers0