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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:48:13+00:00 2026-06-15T20:48:13+00:00

Given a simple example as follows, I’d like some guidance on whether to store

  • 0

Given a simple example as follows, I’d like some guidance on whether to store as a single document vs multiple documents.

class User
{
    public string Id;
    public string UserName;
    public List<Post> Posts;
}

class Post
{
    public string Id;
    public string Content;
}

Once the data is stored, there are times when I will want all the posts for a given user. Sometimes I might want posts across multiple users that meet a particular criteria.

Should I store each User as a document (with Posts embedded), or does it make more sense to store Users and Posts as seperate documents, and have some sort of ID in my post to link it back to a User?

Now, what if each user belonged to an Organization (there will be hundreds of organizations in my application)?

class Organization
{
      public string Id;
      public List<User> users;
}

Should I then stay with the single document approach? In this case I would store one giant document for each organization, which will contain embedded users, which in turn contain embedded posts?

  • 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-15T20:48:14+00:00Added an answer on June 15, 2026 at 8:48 pm

    You should keep them as separate documents. User, Organization, and Post are great examples of aggregate entities, and in Raven, each aggregate is usually its own document.

    Only entities which are not aggregates should be nested in the same document. For example, in Post you might have a List<Comment>. Comment and Post are both entities, but only Post is an aggregate.

    You should instead model them with references:

    public class User
    {
        public string Id { get; set; }
        public string Name { get; set; }
        public List<string> PostIds { get; set; }
    }
    
    public class Post
    {
        public string Id { get; set; }
        public string Content { get; set; }
    }
    
    public class Organization
    {
        public string Id { get; set; }
        public List<string> UserIds { get; set; }
    }
    

    Optionally, you can denormalize some of the data into your references where appropriate:

    public class UserRef
    {
        public string Id { get; set; }
        public string Name { get; set; }
    }
    
    public class Organization
    {
        public string Id { get; set; }
        public List<UserRef> Users { get; set; }
    }
    

    Denormalizing the user’s name into the organization document has the benefit of not needing to fetch each user document when displaying the organization. However, it has the drawback of having to update the organization document any time a user’s name is changed. You should weigh the pros and cons of this each time you consider a relationship. There is no one right answer for all cases.

    Also, you should be considering how data will be really used. In practice, you will probably find that your Organization class may not need a user list at all. Instead, you could put a string OrganizationId property on the User class. That would be easier to maintain, and if you wanted a list of users in an organization, you could query for that information using an index.

    You should read more in the raven documentation on Document Structure Design and Handling Document Relationships.

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

Sidebar

Related Questions

Given a simple C# class definition like: [System.Windows.Markup.ContentProperty(PropertyOne)] public class SimpleBase { public string
Given a simple data set, I would like to be able to calculate a
Given a simple class: public class Person { public string FirstName; public string LastName;
Given a simple parent/child class structure. I want to use linqkit to apply a
I have a very simple class that derives off of the example Say class
A canonical example of patching up an otherwise covariant class is as follows: abstract
Simple one to start the day, given a Dictionary<string, string> as follows: var myDict
I'm trying to follow this simple examples given in the google web store API
I know this should be very simple especially given all the information and example
Can someone give me a simple example involving threads in this manner, please. Problem

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.