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 7641561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:57:20+00:00 2026-05-31T08:57:20+00:00

First off I’m just getting started with RavenDB so please be patient as I

  • 0

First off I’m just getting started with RavenDB so please be patient as I explain the issue. I’m trying to create my first map, map, reduce, transform index. Yeah I know I’m trying to do a lot but I have most of it working.

So first off I do this in my global.asax to make sure that all “ID” properties are used as the identifier on documents.

_documentStore.Conventions.FindIdentityProperty = p => p.Name == "ID";

OK now lets take a look at the index.

public class ProblemListViewIndex : AbstractMultiMapIndexCreationTask<ProblemListView>
{
    public ProblemListViewIndex()
    {
        AddMap<Problem>(problems => from problem in problems
                                    select new
                                    {
                                        ID = problem.ID,
                                        SolutionCount = 0,
                                    });

        AddMap<Solution>(solutions => from solution in solutions
                                      select new
                                      {
                                        ID = solution.ProblemID,
                                        SolutionCount = 1,
                                      });


        Reduce = results => from result in results
                            group result by result.ID
                                into g
                                select new
                                {
                                    ID = g.Key,
                                    SolutionCount = g.Sum(x => x.SolutionCount),
                                };

        Indexes.Add(x => x.ID, FieldIndexing.Analyzed);

        TransformResults = (database, results) => from result in results
                                                  let problem = database.Load<Problem>("problems/" + result.ID.ToString())
                                                  let user = database.Load<User>("users/" + problem.PostedByID.ToString())
                                                  select new
                                                  {
                                                      ID = result.ID,
                                                      PostedByID = problem.PostedByID,
                                                      PostedByName = user.DisplayName,
                                                      SolutionCount = result.SolutionCount,
                                                  };

    }
}

So everything looks good and when I test the index in the RavenDB website I get mixed results. I have duplicate projections. I have the two projections that I expect but two copies of them. Here are what the “ID” looks like on the projection results.

  • problems/194
  • problems/195
  • 194
  • 195

I’m confused but then I went back and looked at the “maps”. My code translated into something different in the created index. Here is what the first map looks like when created initially.

docs.Problems
    .Select(problem => new {ID = problem.__document_id, SolutionCount = 0})

Even being new to RavenDB I see the problem. It’s using the “__document_id” field when I want to use the “ID” field. I change the map in then save the index to the following.

docs.Problems
    .Select(problem => new {ID = problem.ID, SolutionCount = 0})

Once I do that my projection looks exactly as I expected and as I want it.

  • 194
  • 195

My question is what do I need to do in my code to get my index to create using “ID” over “__document_id”?

  • 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-05-31T08:57:22+00:00Added an answer on May 31, 2026 at 8:57 am

    I don’t see what’s wrong here. I#ve put together a test using your code and I get what I have expected:

    public class MultiMapWithTransformAndCustomId
    {
        public class Problem
        {
            public string ID { get; set; }
            public string PostedByID { get; set; }
            public string Foo { get; set; }
        }
    
        public class Solution
        {
            public string ID { get; set; }
            public string ProblemID { get; set; }
            public string Foo { get; set; }
        }
    
        public class User
        {
            public string ID { get; set; }
            public string DisplayName { get; set; }
        }
    
        public class ProblemListViewIndex : AbstractMultiMapIndexCreationTask<ProblemListViewIndex.ReduceResult>
        {
            public class ReduceResult
            {
                public string ID { get; set; }
                public int SolutionCount { get; set; }
                public string PostedByID { get; set; }
                public string PostedByName { get; set; }
            }
    
            public ProblemListViewIndex()
            {
                AddMap<Problem>(problems => from problem in problems
                                            select new
                                            {
                                                ID = problem.ID,
                                                SolutionCount = 0,
                                            });
    
                AddMap<Solution>(solutions => from solution in solutions
                                              select new
                                              {
                                                  ID = solution.ProblemID,
                                                  SolutionCount = 1,
                                              });
    
    
                Reduce = results => from result in results
                                    group result by result.ID
                                        into g
                                        select new
                                        {
                                            ID = g.Key,
                                            SolutionCount = g.Sum(x => x.SolutionCount),
                                        };
    
                Indexes.Add(x => x.ID, FieldIndexing.Analyzed);
    
                TransformResults = (database, results) => from result in results
                                                          let problem = database.Load<Problem>(result.ID.ToString())
                                                          let user = database.Load<User>(problem.PostedByID.ToString())
                                                          select new
                                                          {
                                                              ID = result.ID,
                                                              PostedByID = problem.PostedByID,
                                                              PostedByName = user.DisplayName,
                                                              SolutionCount = result.SolutionCount,
                                                          };
    
            }
        }
    
        [Fact]
        public void Can_do_simple_query()
        {
            using (var documentStore = new EmbeddableDocumentStore
            {
                RunInMemory = true
            })
            {
                documentStore.Conventions.FindIdentityProperty = p => p.Name == "ID";
                documentStore.Initialize();
    
                using (var documentSession = documentStore.OpenSession())
                {
                    documentSession.Store(new User {ID = "users/1", DisplayName = "Daniel"});
                    documentSession.Store(new User {ID = "users/2", DisplayName = "Lang"});
                    documentSession.Store(new Problem {ID = "problems/194", PostedByID = "users/1"});
                    documentSession.Store(new Problem {ID = "problems/195", PostedByID = "users/2"});
                    documentSession.Store(new Solution {ID = "solutions/1", ProblemID = "problems/194"});
                    documentSession.Store(new Solution {ID = "solutions/2", ProblemID = "problems/194"});
                    documentSession.Store(new Solution {ID = "solutions/3", ProblemID = "problems/195"});
                    documentSession.SaveChanges();
                }
    
                new ProblemListViewIndex().Execute(documentStore);
    
                using (var documentSession = documentStore.OpenSession())
                {
                    var results = documentSession.Query<ProblemListViewIndex.ReduceResult, ProblemListViewIndex>()
                        .Customize(x => x.WaitForNonStaleResultsAsOfLastWrite())
                        .ToList();
    
                    Assert.Equal(2, results.Count);
    
                    var daniel = results.First(x => x.PostedByName == "Daniel");
                    var lang = results.First(x => x.PostedByName == "Lang");
    
                    Assert.Equal("problems/194", daniel.ID);
                    Assert.Equal("problems/195", lang.ID);
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off, I'm a real beginer at C# so please be gentle. I'm trying
First off, there's a bit of background to this issue available on my blog:
First off, thank you to everyone on this site...it's been INCREDIBLY helpful in getting
first off this is a class assignment so i would appreciate help but just
First off I am pretty new to C, so I probably just have a
First off, please accept my apologies if this question is basic, I mainly have
First off, this is the error I am getting java.lang.OutOfMemoryError at coderaustin.com.FileEncryptor.encryptFile(FileEncryptor.java:56) at coderaustin.com.Main.onCreate(Main.java:41)
First off... i'm only just coming to jquery, so... if anyone has time to
First off, the barest bones of the project I wish to create is a
First off, I would like to say that I am just starting with PHP

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.