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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:10:52+00:00 2026-05-20T05:10:52+00:00

Lets say we have the following document structure: class BlogPost { [MongoIdentifier] public Guid

  • 0

Lets say we have the following document structure:

class BlogPost
{
   [MongoIdentifier]
   public Guid Id{get;set;}
   public string Body{get;set;}
   ....
}

class Comment
{
   [MongoIdentifier]
   public Guid Id{get;set;}
   public string Body {get;set;}
}

If we assume that multiple users may post comments for the same post, what would be the best way to model the relation between these?

if Post have a collection of comments, I might get concurrency problems, won’t I ?

And placing a FK like attribute on Comment seems too relational , or?

  • 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-20T05:10:53+00:00Added an answer on May 20, 2026 at 5:10 am

    You basically have two options: 1. Aggregate comments in the post document, or 2. Model post and comment as documents.

    If you aggregate the comments, you should either a) implement a revision number on the post, allowing you to detect race conditions and implement handling of optimistic concurreny, or b) add new comments with a MongoDB modifier – e.g. something like

    var posts = mongo.GetCollection<Post>();
    var crit = new { Id = postId };
    var mod = new { Comments = M.Push(new Comment(...)) };
    
    posts.Update(crit, mod, false, false);
    

    If you model post and comment as separate documents, handling concurrency is probably easier, but you lose the ability to load a post and its comments with a single findOne command.

    In my opinion, (1) is by far the most interesting option because it models the post as an aggregate object, which is exactly what it is when you put your OO glasses on :). It’s definitely the document-oriented approach, whereas (2) resembles the flat structure of a relational database.

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

Sidebar

Related Questions

Lets say I have the following code: abstract class Animal case class Dog(name:String) extends
Lets say I have the following: public class MyObject { [Bindable] public var foo:int
Lets say I have the following code public static string GetXMLValue() { XDocument settingsFile
Let's say I have the following class: public class Test<E> { public boolean sameClassAs(Object
Lets say I have the following XML document: <response> <businessEntity> <ABN> <identifierValue></identifierValue> <isCurrentIndicator></isCurrentIndicator> <replacedIdentifierValue
Using Mongoid, let's say I have the following classes: class Map include Mongoid::Document embeds_many
Let's say I have the following HTML: <table id=foo> <th class=sortasc>Header</th> </table> <table id=bar>
Let's say we have the following method declaration: Public Function MyMethod(ByVal param1 As Integer,
Let's say I have the following class X where I want to return access
So i have the following structure <div id=container> <div id=head></div> <div id=body></div> <div id=foot></div>

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.