0

I'm trying to count a distinct value with pymongo, my code looks like :

account_log = mongo["account_log"].find({"uuid": guid}).distinct("logged_number")
total["account"] = len(mongo["group_member"].find({ "group_id": {"$in": groups}}).distinct("phone"))

the distinct inside len() was very very slow, is there another way to count the distinct result, thank you

krishna Prasad
  • 3,541
  • 1
  • 34
  • 44
  • Please check the answer at https://stackoverflow.com/questions/14924495/mongodb-count-num-of-distinct-values-per-field-key – krishna Prasad Dec 15 '19 at 12:23
  • 1
    @krishnaPrasad i already check that answer, and i ask "faster way", not just counting a distinct value –  Dec 15 '19 at 13:48
  • If given [answer](https://stackoverflow.com/a/48695921/3710490) doesn't feet your expectation, there is no any "faster way" to count distinct values. – Valijon Dec 15 '19 at 17:44

0 Answers0