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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:17:39+00:00 2026-05-27T05:17:39+00:00

I come from a MySQL background and am trying to wrap my head around

  • 0

I come from a MySQL background and am trying to wrap my head around MongoDB. In particular, I’m struggling to conceptualize how I should model n:n relationships the “Mongo way.”

For this example, let’s say we have two collections: users and interests. We need to be able to represent or query for several things in our data:

  • User’s interests
  • User’s rating of interest, e.g. “like” or “dislike”
  • Users with a given interest
  • Counter (which can be incremented/decremented) of each rating of the interest
  • Interest name

In MySQL, I would have created a users_interests table indexed on both user IDs and interest IDs. For the counter, I would have had separate columns for each rating type, and each time a user rated/un-rated an interest, done a transaction to ensure that the counts were never false.

I’ve tried reading about some schema designs, but to no avail.

Can you help a lost soul find the way?

  • 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-27T05:17:39+00:00Added an answer on May 27, 2026 at 5:17 am

    Great question. Let me first outline a bit of how the N:N relationship works then I’ll go into detail on each of your bullet points.

    N:N in MySQL normally you have your pivot table associating between your user and interests (user_interests table). In mongo you do this a bit differently. You still have a users and interest collection, however instead now, you store a list of keys under interests for a user. SO something like this:

    User Collection {
          "name":"Josh",
          "user":"jsmith",
          "interests":[
               {
                "_id":12345,
                "rating":"like"
               },
               {..}..
          ]
    }
    

    By storing your interests in a list which is keyed off on your interest table, you can perform each of the actions you require. If you wanted to do a query you’d od it based on the ID which is in the interest table then do a query using the $in modifier.

    Now for your interests collection I’d do the following:

    User Interest {
          "_id":objectId
          "label":"Swimming",
          "count":intValue
    }
    

    When adding an interest to a users document, the count variable would then depend on the definition of your ratings. If you’re storing your ratings in a separate area (or in logic), then the value you assigned to them would be what you relate then to the int value in interest. IE: User rates it meh (which has a value of 1) then you would add 1 to the count value.

    Hopefully this is helpful and has at the very least brought about some other ideas on how to structure it!

    Best of luck, remember MONGO IS AWESOME.

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

Sidebar

Related Questions

I come from MySQL background and I am trying to learn MongoDB. I have
I come from a mysql background where if I want to insert a record
I come from a linux/apache/php/mysql background. For my current project, I am forced to
i need to display the drop down when the day is come from mysql
I'm running into two issues with Derby and Mongo. I come from a MySQL
I come from a Java background and am getting more into .NET, what are
I come from a C++ background and I've been working with C# for about
I come from a php background and in php, there is an array_size() function
I come from a C# background and I am working on a C++ project.
I come from a .NET background and need to do a web project 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.