How to achieve Stack Overflow style reputation using RavenDB?

45 views
Skip to first unread message

Chase Florell

unread,
Feb 26, 2012, 2:06:03 PM2/26/12
to ravendb
I've got a project that is very similar to SO. So taking SO as an
example, how can I achieve this use case in Raven?

A user gains reputation for doing various activities on the site.
As their rep increases, each post they make has their rep associated
with their name.

In SQL server, I have a Rep table with each single activity
represented and a TotalRep field in the users table.

If I use RavenDB, the relevant user details will be stored in the
document with each post... How then would you insert the dynamically
changing reputation into the ViewModel? The best I can think of is to
have a separate query for each user that's being displayed on the
page. The problem with this is that if there are 30 comments to a
question, then there will be one query for the question and an
additional 30 queries to get the reputation.

Is there a better way to achieve this?

Oren Eini (Ayende Rahien)

unread,
Feb 26, 2012, 3:16:47 PM2/26/12
to rav...@googlegroups.com
Here is one option. The User's reputation is stored inside the User document.
Each question/comment include the user's id.

You can then query it using:

session.Query<Question>()
   .Customize(x=>x.Include("UserId").Include("Answers,UserId").Include("Answers,Comments,UserId") )
   .ToList();

This will load the user who asked the question, the users who answered the question and all of the comments in a single query to the database.

Chase Florell

unread,
Mar 4, 2012, 11:56:55 AM3/4/12
to ravendb
Here's how I expected the json to look for the [question] document
(incomplete, but you get the point)

{
"userId": 1,
"questionId": 1,
"questionTitle": "MyTitle",
"question": "howdoImanageRavenDB?",
"questionDate": "4/26/09",
"questionAnswers": [
{
"answerId": 1
"userId": 2,
"answer": "Here's an answer to your question",
"answerDate": "4/26/09"
}
]

On Feb 26, 1:16 pm, "Oren Eini (Ayende Rahien)" <aye...@ayende.com>
wrote:
> Here is one option. The User's reputation is stored inside the User
> document.
> Each question/comment include the user's id.
>
> You can then query it using:
>
> session.Query<Question>()
>
>  .Customize(x=>x.Include("UserId").Include("Answers,UserId").Include("Answer s,Comments,UserId")
> )
>    .ToList();
>
> This will load the user who asked the question, the users who answered the
> question and all of the comments in a single query to the database.
>

Chris Marisic

unread,
Mar 6, 2012, 12:45:27 PM3/6/12
to rav...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages