1

I'm trying to find the user with the most friends from a Yelp dataset on studio3t using mongodb. I am using studio3t's aggregation tool.

First I selected "name" and "friends" with $project

Next, I wanted to group by the name of each user, and then sum the number of friends that correspond to that user

{
    _id : "$name",
    numberoffriends: {$sum : "$friends"}
}

However, I get a result that returns the names but returns a sum value of 0 for each name, which isn't correct.

Should I be using a sum operator? or is there a better operator for this function such as count?

Saurabh Bhandari
  • 2,438
  • 4
  • 26
  • 33
Jsb54
  • 11
  • 1
  • add mongodb tag as well and share your work what you tried till now. Share sample data and expected result as well. – Rahul Jain Apr 26 '18 at 06:01

1 Answers1

0

Friends value is not integer. So $sum will not work.
Try using $count instead of $sum which will count the number of records

Rahul Jain
  • 1,319
  • 7
  • 16