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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:43:33+00:00 2026-05-24T05:43:33+00:00

Let’s say that my models are User and Project. Each user can be assigned

  • 0

Let’s say that my models are User and Project. Each user can be assigned to many projects and each project can have many users assigned. This is a typical many to many relationship and could be stored as (source):

# The user document.
{
  "_id" : ObjectId("4d3ed089fb60ab534684b7e9"),
  "project_ids" : [ ObjectId("4d3ed089fb60ab534684b7f2") ]
}

# The project document.
{
  "_id" : ObjectId("4d3ed089fb60ab534684b7f2"),
  "user_ids" : [ ObjectId("4d3ed089fb60ab534684b7e9") ]
}

The problem is, I would like to assign more data describing this relationship, e.g. a role that the user has in the project (admin, manager, etc.). In a RDBMS I would just add an additional column to the join table. In MongoDB, I really don’t know how to go about this.

Should I create an additional embedded document in either User or Project? I was thinking about something like this:

# The project document.
{
  "_id" : ObjectId("4d3ed089fb60ab534684b7f2"),
  "assigned_users" : [
    { user_id: ObjectId("4d3ed089fb60ab534684b7e9"), role: "admin" },
    ...
  ]
}

But I guess a query for getting all user’s projects would become quite complicated, right?

I’m using Mongoid, but would be grateful for any general solution (and then I’ll figure out how to map this to Mongoid 😉
Also, I can’t change the database to RDBMS.

  • 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-24T05:43:35+00:00Added an answer on May 24, 2026 at 5:43 am

    How about storing everything you know about a User inside the Users collection?

    {
      "_id": ObjectID("..."),
      "projects": [
        { "role": "admin", "project_id": ObjectId("...") },
        { "role": "manager", "project_id": ObjectId("...") }
      ]
    }
    

    Querying would take place on the Users collection.

    // find all admins on a project, for example
    db.Users.find( { "projects" : 
                      { "role" : "admin", "project_id": ObjectId("...") } })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say that I have a set of relations that looks like this: relations
Let's say that I have classes like this: public class Parent { public int
Let's say I'm creating an OpenGL game in C++ that will have many objects
Let's say that we have an ARGB color: Color argb = Color.FromARGB(127, 69, 12,
Let's say I have a simple Login servlet that checks the passed name and
Let's say I have this: SolutionSet(const SolutionSet &solutionSet) { this->capacity_ = solutionSet.capacity_; this->solutionsList_ =
Let's say I have saved this kind of data (some text '.date(d).' some text)
Let's say I have this: float i = 1.5 in binary, this float is
Let's say on a page I have alot of this repeated: <div class=entry> <h4>Magic:</h4>
Let's say I can call a method like this: core::get() . What is the

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.