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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:29:41+00:00 2026-05-27T16:29:41+00:00

At first I’m trying to make a rally (you know cars with drivers…) database.

  • 0

At first I’m trying to make a rally (you know cars with drivers…) database. I have two collections: drivers { name, address, sex, ... } and then another one tournaments { name, location, price, ... }

I try to keep it simple. In a tournament there should be drivers (because a tournament without drivers…well its not nice ^^). And there is my problem, in a normal sql database I could select two primary keys (lets say name in drivers and name in tournaments – just to keep it simple, I know name as primary key is not nice). And because its an m..n relationship (is it right?) I would make a 3. Table with the two primary keys. OK that would be easy. But how should I solve this problem in mongodb. I thought something like: tournaments { name, location, price, ... drivers { driver_1, ..., driver_n } } , but im not sure. I’m using Java so I could make some special Classes which one is handling this relationship problem? I don’t understand the other mongodb tutorials. Any ideas? Thank you for any help!

  • 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-27T16:29:42+00:00Added an answer on May 27, 2026 at 4:29 pm

    There are a few ways to do this:

    1. As @Gianluca describes you can perform this linking manually by adding a driver’s _id ObjectId or another identifying property (probably one you have a unique index on) to a “drivers” array in a tournament document. e.g. tournament : { ... drivers : ["6019235867192384", "73510945093", ...]}
    2. Another option specifically built for this referencing is the DBRef specification which provides a more formal method probably more similar to what you’re familiar in the SQL world. DBRef is supported by the java driver and allows you to scope your reference to a collection (basically saying where this reference comes from). I wouldn’t be surprised if in the future versions of MongoDB cross-collection queries will be supported, although they are not currently.

    More information here.

    Also if you aren’t using a DAO framework I would suggest Morphia which supports DBRef with a nice @Reference annotation.

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

Sidebar

Related Questions

First you should know I have looked into many questions and none of them
First, I have a list of QWidget s that I won't know the length
First, a little background (greatly simplified): I have two classes, one called Entity and
First of all, I know how to build a Java application. But I have
first take a look on this picture from localScope app : i have 2
First sorry for my english. I am currently trying to develop a JAVA webservice
first I used onDestroy() method as below to make something when my app is
First I want to thank you guys here, because your posts have gotten me
First, I have a dbcontext factory which is defined public class DatabaseFactory : Disposable,
First of all, some background: I'm trying to get in a list of integers

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.