How to Join User info to a Review Collection ? (Profile/Review case)

I’m new in MongoDB and i’m trying to do a kind of “profile/reviews” module. I’m saving this two entities into two different collections because i read about some limitations of having a lot of nested elements (in this case, reviews will grow a lot).

My schemas are:

Review:

{
    "_id" : ObjectId("56073ea299f4ebd05df813a8"),
    "rate" : "0", 
    "owner" : "xub32YLjc4xJa38aM",
    "to" : "8zqCPbkwYMfajyFQx",
    "createdAt" : ISODate("2015-09-27T00:56:02.328Z")
}

Where:

  • Rate: Can be 0 or 1 (bad and good, simple)
  • Owner: User ID who made the review
  • To: Profile ID that was made a review

Profile:

{
    "_id" : "8zqCPbkwYMfajyFQx",
    "CI" : "19",
    "firstName" : "Alan",
    "lastName" : "Brito Delgado",
    "gender" : "m",
    "bio" : "lorem ipsum haha a bio right here pls",
    "birthdate" : ISODate("2015-09-26T01:54:46.687Z"),
    "specialty" : "Medico generalshhh",
    "worksIn" : "Integramedica",
    "academicInformation" : "Medicia UC 2010",
    "avatar_url" : "img/doctor-1.png",
    "certified" : false
}

Where:

  • CI, Specialty, WorksIn, AcademicInformation and Certified are the fields that i use to filter profiles

My problem is that i want to make a “Ranking view” where people can add filters to view a ranking based on their filters, and, i don’t know how join information about the profile and the reviews count. (Ranking is based on the count of good reviews)

I have an approach of how to know the count of “good” reviews grouped by profile, but, i don’t know how to append the “profile” information:

db.reviews.group({
  key: {to:1},
  cond: {rate:"1"},
  reduce: function(curr, result){
      result.count++;
  },
  initial: { count: 0 }
})

EXAMPLE PROTOTYPE
enter image description here

It’s possible with my current model? or i need to nest profile with reviews or append user to review? (with this second approach, i think i will have user info not to date)

PS: I review Profiles, not users so, users are different than profiles

Hi, try this packacke : collection-helpers

Have you tried this reywood:publish-composite package?

I found this package very very useful, but, i can’t realize how can i make my “group by” and then, add the user related ?

Like i said to nxcong, i found this package useful, and i like the flexibility, but, where i include my “group by”? its my big issue :frowning:

Hi. please review : http://meteorpad.com/pad/WFrutDi4H6fWfZX9S/Leaderboard-new

Hi,

I recommended package: https://atmospherejs.com/universe/collection

You can make helpers or remote methods on doccument or collection.
There are predefined methods on documents e.g. doc.update({$set: {title:‘New Title’}})
Many others features like possibility of attaching many schemas on collection, hooks, mixins

1 Like