I am new to RavenDB and still love it. I have one remaining index for my project.
Problem
I have thousands of responses to polls (ie, β Submissions β), and each view has many answers to specific questions (ie, β Answers β), and each answer has a set of parameters that have been selected (i.e. . " Values ").
Here's what one Submission looks like:
{ "SurveyId": 1, "LocationId": 1, "Answers": [ { "QuestionId": 1, "Values": [2,8,32], "Comment": null }, { "QuestionId": 2, "Values": [4], "Comment": "Lorem ipsum" }, ...more answers... ] }
Additional problem: I have the ability to filter SurveyId, LocationId, QuestionId, Creation Date. As far as I understand, this was done at the time of the request ... I just need to make sure that these properties are present as a result of the conversion (or is it the result of reduction? Or both?). If I'm right, then this is not a problem.
Desired Result
We need one object for each survey, which gives the sum of each option. I hope he will explain:
[ { SurveyId: 1, QuestionId: 1, NumResponses: 976, NumComments: 273, Values: { "1": 452, // option 1 selected 452 times "2": 392, // option 2 selected 392 times "4": 785 // option 4 selected 785 times } }, { SurveyId: 1, QuestionId: 2, NumResponses: 921, NumComments: 46, Values: { "1": 325, "2": 843, "4": 119, "8": 346, "32": 524 } }, ... ]
My attempt
I am not very far away and I think this post guides me on the right path, but it does not help me with the list of values, I searched and searched, but I can not find any direction for what to do with the nested array. Here is what I still have:
MAP:
from submission in docs.Submissions from answer in submission.Answers where answer.WasSkipped != true && answer.Value != null select new { SubmissionDate = submission["@metadata"]["Last-Modified"], SurveyId = submission.SurveyId, LocationId = submission.LocationId, QuestionId = answer.QuestionId, Value = answer.Value }
REDUCE:
??
Transform:
from result in results from answer in result.Answers where answer.WasSkipped != true && answer.Value != null select new { SubmissionDate = result["@metadata"]["Last-Modified"], SurveyId = result.SurveyId, LocationId = result.LocationId, QuestionId = answer.QuestionId, Value = answer.Value }
For what it's worth, it's hosted on RavenHQ.
It has been so long that I have been working on it and cannot understand. Any help in getting me to the desired result is greatly appreciated!