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

  • Home
  • SEARCH
  • 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 4329798
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:52:21+00:00 2026-05-21T09:52:21+00:00

I am currently trying to figure out, how Nosql databases handle relations and what

  • 0

I am currently trying to figure out, how Nosql databases handle relations and what the unique Id of a Document really means.

Maybe I am expecting too much of MongoDb or I haven’t grasp the concept of relations in NoSQL databases yet.

Basically, the following test fails, and I wonder how one would model such a relation between Users and Groups (which is a 1 : 0..N relation).

[TestFixture]
public class MongoDbExamples
{

    private MongoServer _mongoServer;

    [TestFixtureSetUp]
    public void FixtureSetUp()
    {
        _mongoServer = MongoServer.Create();
    }

    [TestFixtureTearDown]
    public void FixtureTearDown()
    {
        _mongoServer.Disconnect();
    }


    [Test]
    public void RelationTest()
    {
        var database = _mongoServer.GetDatabase("StackoverflowExamples");

        var p = new Person() { Name = "Testperson" };
        var persons = database.GetCollection<Person>("Persons");
        persons.Save<Person>(p);

        var group = new Group() { Description = "A fancy descriptor" };
        group.Add(p);
        var groups = database.GetCollection<Group>("Groups");
        groups.Save<Group>(group);

        var readPerson = persons.FindOneById(p.Id);
        readPerson.Name = "a different name";
        // since the id hasn't change this is an update of the original person:
        persons.Insert<Person>(readPerson);

        // and I thought that it should be reflected in the group as well:
        var readGroup = groups.FindOneById(group.Id);
        Assert.AreEqual(readPerson.Id, readGroup.persons[0].Id); // this passes, the id is the same
        Assert.AreEqual(readPerson.Name, readGroup.persons[0].Name); // this fails, the groups person still has the old name
    }

}

Are there best practices for such relations? E.g. Should search for all person in all Collections/Documents and exchange those found with the matching person of the persons collection? Or are relations something which NoSQL databases aren’t good at and I should avoid relations (I wonder how to use a NoSQL-DB in a bigger system with more complex object graphs then)?

  • 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-21T09:52:22+00:00Added an answer on May 21, 2026 at 9:52 am

    There is no such thing as relations or auto-updates of related collections. Seems like you expect mongo to behave like an ORM, but that is not what it does, at least not with the C# driver. If you want to save a Person and a Group you will have to save them both individually.

    Rather than storing full person objects inside the group objects, you should store just the person ids instead. Then use those Ids to do a lookup of the person when you need the person data.

    Also, you may wan to read the docs on dbref.

    http://www.mongodb.org/display/DOCS/Database+References#DatabaseReferences-DBRef

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

Sidebar

Related Questions

I am currently trying to figure out what CallLog.Calls.NEW means. The documentation says: Whether
I am currently trying to figure out how you can bind multiple fields in
I am currently trying to figure out how sms classes are correctly represented in
I'm currently trying to figure out how to perform manual windows authentication in our
I am currently trying to figure out how to do move semantics correctly with
I'm currently trying to figure out which implementation of JSR-311 I'm going to recommend
I am currently trying to figure out the best way to create a .xls
I am currently trying to figure out what the best way is to create
I'm learning JavaScript and I'm currently trying to figure out why (in Spidermonkey )
I am currently trying to figure out a way to have an Android application

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.