Query to count the number of documents for each user