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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:33:04+00:00 2026-06-12T03:33:04+00:00

I am using mongodb from C#. I have an entity definition, and I want

  • 0

I am using mongodb from C#.

I have an entity definition, and I want reference another entity from this one.
(Note the embed is not an option)

I know that I can insert a field with the other entity id in the first one. That is something like:

class Person
{
    public object Id { get; set; }
    public string Name { get; set; }
    public object Pet { get; set; }  // note here I have the pet Id and not the pet.
}


class Pet
{
    public object Id{get;set;}
    .....
}

Now, here I am inserting in my domain logic business some rare mechanics.

Then my question is: Is out there some practices that allow me hide this kind of issues to
my domain layer, I mean in my domain I just want have something like:

class Person
{
   public object Id { get; set; }
   public string Name {get; set; }
   public Pet Pet { get; set; }  // note here I have the pet.
}


class Pet
{
   public object Id{get;set;}
   .....
}

In my domain I want focus in the coding instead of the mechanics.

  • 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-12T03:33:06+00:00Added an answer on June 12, 2026 at 3:33 am

    My recommendation would be not to use mongodb, which is a nosql aka document based db , as a relational db. The recommended way for modelling data in nosql is to treat each document as an aggregate root (http://lostechies.com/jimmybogard/2008/05/21/entities-value-objects-aggregates-and-roots/) i.e. making a distinction between entity and value object is very crucial Value objects should not have ids. In the mongodb tutorial below
    http://www.codeproject.com/Articles/87757/MongoDB-and-C

    Comments are value objects. So the main question is pet a value object and require an ID.
    If it does not then remove ID from Pet class and embed pet inside Person class. If it requires an ID then keep ID field in Pet class , save it as its own document and store Pet ID in Person class. This is the recomended pattern for nosql data modelling.

    A neat trick to evaluate if your data model suits nosql is to ask yourself does this document provide the complete information for a Person in the context ( a person who owns a pet) in one trip or document then usually you are using it incorrectly. Though for a different nosql database the following articles convey this concept very well

    http://ayende.com/blog/4465/that-no-sql-thing-the-relational-modeling-anti-pattern-in-document-databases
    http://ayende.com/blog/4466/that-no-sql-thing-modeling-documents-in-a-document-database

    Hope this helps.

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

Sidebar

Related Questions

I'm using the JavaScript mongodb driver from nodejs. I want to do this query
Using MongoDB I'm trying to copy a database from one server to another. My
first time i'm using MongoDB. I have read this example: SELECT a,b FROM users
I have very interested in using MongoDB it seems awesome. But I'm from a
I just installed mongodb from Synaptic (Using ubuntu 11.10). I'm following this tutorial: http://howtonode.org/express-mongodb
I am using mongoose/nodejs to get data as json from mongodb. For using mongoose
I successfully stored image files in MongoDB using PHP, when i retrieve images from
I'm using mongodb 2.1 and how to translate this query into php db.counter.aggregate([ {
I'm using MongoDB as a backend for my project, but I don't specifically want
I am using mongodb in java for one of my projects. User is going

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.