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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:53:15+00:00 2026-05-28T03:53:15+00:00

This question is for all NoSQL and specially mongoDB experts out there. I started

  • 0

This question is for all NoSQL and specially mongoDB experts out there. I started by designing a relational DB for a project but client wants us to use a DB that can easily scale. To achieve this we have decided to use mongoDB. These days I am having trouble mapping my relational model for NoSQL. I have a users table which has a many-to-many relation with a lot of other tables as illustrated below:

relational DB

I have a few options when converting it for mongoDB:

Option 1 (with complete rows in users):

users:{
  _id:<user_id>,
  battles:{[battle1, battle2, ...]},
  items:{[item1, item2, ...]},
  locations:{[location1, location2, ...]},
  units:{[unit1, unit2, ...]},
}

battles:{
  <battle_info>
}

locations:{
  <location_info>
}

units:{
  <units_info>
}

items:{
  <items_info>
}

Option2 (with only foreign keys in users):

users:{
  _id:<user_id>,
  battles:{[battle1_id, battle2_id, ...]},
  items:{[item1_id, item2_id, ...]},
  locations:{[location1_id, location2_id, ...]},
  units:{[unit1_id, unit2_id, ...]},
}

battles:{
  <battle_info>
}

locations:{
  <location_info>
}

units:{
  <units_info>
}

items:{
  <items_info>
}

Option 3 (user ids in other tables):

users:{
  _id:<user_id>,
}

battles:{
  <battle_info>,
  user:{[user1_id, user2_id, ...]}
}

locations:{
  <location_info>,
  user:{[user1_id, user2_id, ...]}
}

units:{
  <units_info>,
  user:{[user1_id, user2_id, ...]}
}

items:{
  <items_info>,
  user:{[user1_id, user2_id, ...]}
}

Option 1 has a lot of duplication as we are adding complete rows of other tables. One issue I see in this is that if a certain item or battle is updated, we will have to find all occurrences of it in users table and update them as well. But this gives us the advantage of always having a complete users object which can be handed to client application at time of login.

Option 2 is more relational where we only have mongoIds of other tables in users table. Advantage of this options is that updating a battle or item doesn’t have much cost as rows are referenced not copied. On the other hand, when user logs in we will have to find all referenced units, battles, items, and locations to respond with a complete users object.

Option 3 is opposite to option 2 where mongoIds of users table are kept in other tables. This option doesn’t appeal much to me.

I would really appreciate of someone can guide me or come up with a better model.

Edit:

Basically this is an mmorpg game where multiple clients apps will connect to server through webservices. We have got a local db at client to store data. I want a model through which server can respond with a complete user object and then update or insert data changed on client apps.

  • 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-28T03:53:16+00:00Added an answer on May 28, 2026 at 3:53 am

    First, NoSQL is not one size fits all. In SQL, almost every 1:N and M:N relation is modeled in the same way. The NoSQL philosophy is that the way you model the data depends on the data and its use patterns.

    Second, I agree with Mark Baker: Scaling is hard, and it’s achieved by loosening constraints. It’s not a technology matter. I love working with MongoDB, but for other reasons (no need to code ugly SQL; no need for complicated, bloated ORM; etc.)

    Now let’s review your options:
    Option 1 copies more data than needed. You will often have to denormalize some data, but never all of it. If so, it’s cheaper to fetch the referenced object.

    Option 2/3 they are very similar. The key here is: who’s writing? You don’t want a lot of clients having write-access to the same document, because that will force you to use a locking mechanism, and/or restrict yourself to modifier operations only. Therefore, option 2 is probably better than 3. However, if A attacks B, they’d also trigger a write to user B, so you have to make sure your writes are safe.

    Option 4 Partial denormalization: Your user object seems to be most important, so how about this:

    user { 
     battles : [ {"Name" : "The battle of foo", "Id" : 4354 }, ... ]
     ...
    }
    

    This will make it easier to show e.g. a user dashboard, because you don’t need to know all the details in the dashboard. Note: the data structure is then coupled to details of the presentation.

    Option 5 Data on edges. Often, the relation needs to hold data as well:

    user {
     battles : [ {"Name" : "The battle of foo", "unitsLost" : 54, "Id" : 34354 }, ... ]
    }
    

    here, unitsLost is specific to the user and the battle, hence the data sits on the edge of the graph. Contrary to the battle’s name, this data is not denormalized.

    Option 6 Linker collections. Of course, such ‘edge-data’ can grow huge and might even call for a separate collection (linker collection). This fully eliminates the problem of access locks:

    user { 
      "_id" : 3443
    }
    
    userBattles {
      userId : 3443,
      battleId : 4354,
      unitsLost : 43,
      itemsWon : [ <some list > ],
      // much more data
    }
    

    Which of these is best depends on a lot of details of your application. If users make a lot of clicks (i.e. you have a fine-grained interface), it makes sense to split up objects like in option 4 or 6. If you really need all data in one batch, partial denormalization doesn’t help, so option 2 would be preferable. Keep in mind the multiple writer problem.

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

Sidebar

Related Questions

This question doesn't relate only to MouseEvent.CLICK event type but to all event types
This is odd, but we have written an asp.Net web application (all's well there)
I'm developing Wordpress theme for my friend's company, but this question is all about
Hey all -- this question is specifically about a gender validation, but I'm interested
Is this even a reasonable question to ask? I know most NoSQL databases all
I've seen this question asked all over the net, but haven't seen an answer
First of all i read this question: Firebird database replication But i dont want
This question is all over SO, but no one seems to have had the
This question is related to another question which I asked yesterday! List all links
I ask this question in the hope of collecting all the incompatible changes/bugfixes in

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.