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 }
})
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