How do I get the number of all unique name
fields in table
collections? In SQL the code would look something like this:
select count(*) from (
select name from table
group by name
)
My first guess was this
aggregated_sums = table.aggregate([{"$group": {"_id": "$name", "count":{"$sum": 1}}}])
print(len(list(aggregated_sums)))
But I'm afraid that in my scenario aggregated_sums might contain tens of millions of records.