Filter a static RavenDB map/reduce index

こ雲淡風輕ζ 提交于 2019-12-06 06:07:49

The index you have currently aggregates all of the data together, by the SurveyId and QuestionId. If you want it broken out by date or location, those are new indexes. You would simply add the fields you wanted to the map, include them in the grouping key, and pass them through in the result. Then you can easily query by those keys.

When you have different grouping keys, you can't consolidate that into a single index. You have to have multiple indexes. For example, I might call the index you have above Submission_TotalsBySurveyAndQuestion, and another index might be Submission_TotalsBySurveyAndQuestionPerLocation.

Think of it this way - right now, you can include a Where or OrderBy in your query that goes against the SurveyId or QuestionId - because those are grouping keys in your index. If you want to filter or sort by LocationId, that has to be included.

One word of caution, you said:

I'd also like to filter by Submission date (from metadata)

The only date RavenDB gives you in the metadata (by default) is the Last-Modified date. Any edit to the document will update this. So if the submission date is important to you, then you should probably keep it in your own property.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!