I have documents in RavenDb that may look something like this:
{ "Id": "obj/1", "Version": 1 },
{ "Id": "obj/1", "Version": 2 },
{ "Id": "obj/1", "Version": 3 },
{ "Id": "obj/1", "Version": 4 },
{ "Id": "obj/2", "Version": 1 },
{ "Id": "obj/2", "Version": 2 },
{ "Id": "obj/2", "Version": 3 },
{ "Id": "obj/3", "Version": 1 },
{ "Id": "obj/3", "Version": 3 }
I’m trying to create an index that would give me:
- The sequences “obj/1” and “obj/2”, preferably grouped by Id.
- Not the sequence “obj/3”, since its not yet complete
How would I do this?
I managed to solve it. I’m not sure it is the optimal solution but it seems to work.
With query:
I group the documents by Id and then take all
version + 1except allversion, which for an original sequence of1, 2, 3will be2, 3, 4 except 1, 2, 3, which gives me4(which is why I use theCount() == 1. But if there is a hole in the sequence, the count would be greater than 1, and therefore excluded from the results.