Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8474857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:44:14+00:00 2026-06-10T17:44:14+00:00

I have documents in RavenDb that may look something like this: { Id: obj/1,

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T17:44:15+00:00Added an answer on June 10, 2026 at 5:44 pm

    I managed to solve it. I’m not sure it is the optimal solution but it seems to work.

    class SequenceIndex : AbstractIndexCreationTask<MyObject>
    {
        public EventSequenceIndex()
        {
            Map = objects => from d in docs
                             orderby d.Version
                             select new
                             {
                                 Id = d.Id,
                                 Version = d.Version
                             };
    
            TransformResults = (database, results) => 
                from result in results
                group result by result.Id into g
                where g.Select(d => d.Version + 1)
                   .Except(g.Select(d => d.Version))
                   .Count() == 1
                select new
                {
                    Id = g.Key,
                    Objects = g
                };
        }
    }
    

    With query:

    var events = session.Query<MyObject, SequenceIndex>()
        .As<MySequenceObjectView>()
        .ToArray();
    

    I group the documents by Id and then take all version + 1 except all version, which for an original sequence of 1, 2, 3 will be 2, 3, 4 except 1, 2, 3, which gives me 4 (which is why I use the Count() == 1. But if there is a hole in the sequence, the count would be greater than 1, and therefore excluded from the results.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In RavenDB, I have a document that looks like this: public class SystemNotification {
I have JSON documents in RavenDB that are in this format. { Privilege: [
I have something like this in RavenDb: Path [hasMany] Goals [hasMany] Achievements So I
I have documents similar to this in RavenDB: public class MyClass { ... public
I have documents scanned as .jpg pictures in a folder and I would like
I have documents in Mongo that contain questionnaire-like data (company's name, address, phone numbers,
I have something that looks like the following document structure: public class Document {
So I have this web app that in theory may one day become a
I would like to have a reference between two entities stored in the RavenDB
I have a document class that contains a list of tags. Something like: class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.