How does mongodb use aggregate to count the total number of non-duplicated fields in a group?

there is data like this:

clipboard.png

I want to use aggregate to group group by p, and then count the sum of ac, cc in each province, which can be done. The question is: I want to count the total number of tc in each province (do not repeat)? For example, Fujian is 3, Guangdong is 1, Hubei is 1, what method can be used to do so?

Feb.28,2021
Menu