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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:50:55+00:00 2026-05-30T22:50:55+00:00

I have 3 table in SQL that have many-to-many relation.The first table account have

  • 0

I have 3 table in SQL that have many-to-many relation.The first table “account” have 3 field (AccountId,UserName,Email).The second table “device” have 2 field (DeviceId and DeviceCode) and table “Association” have 4 field (AccountId,DeviceId,LastActivityDate,HasException)

How to convert them to mongoDB.
From suggestion of mongodb.org I embed collection “Associaton” into device collection and account collection but the field “LastAccessDate” always was updated every time when my system have new transaction.

-Account collection:
{

“UserName” : “xxx”,
“Email” : 1,

“Association” : [{
“DeviceId” : “4f45c4b73174ec818148d5c5”,
“LastActivityDate” : “Thu, 23 Feb 2012 11:44:19 GMT +07:00”,
“HasException” : false
}, {
“DeviceId” : ObjectId(“4f45c5e93174ec818148d5c7”),
“LastActivityDate” : “Thu, 23 Feb 2012 11:52:05 GMT +07:00”,
“Exception” : null
}]
}

Device collection:
{

“DeviceCode” : “abcjxhcbxkjcnxkcjhdiofjdojdlkdknd”,
“Associations” : [{
“AccountId” : “34fdgfdy5676”,
“LastActivityDate” : “02/03/2012”,
“HasException” : false
}, {
“AccountId” : “34fdgfdy5dd676”,
“LastActivityDate” : “02/03/2012”,
“HasException” : true
}],

}

  • 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-30T22:50:56+00:00Added an answer on May 30, 2026 at 10:50 pm

    I see multiple solutions for your problem:

    Seldom updates

    To avoid joins, that have to be done client-side in NoSQL databases, put everything into one collection. If you do not update very often, you could do

    {
       _id,
       LastAccessDate,
       HasException,
       Account : {
            AccountID,
            UserName,
            Email },
       Device : {
            DeviceID,
            DeviceCode }
    }
    

    This results in duplicate data, but if performance (no joins) comes before memory efficiency, it’s probably a suitable solution for you. Since the data is stored multiple times, updates are more demanding for the server. I.e. updating the Email address would look like

    db.myColl.update({"Account.UserName" : "User ToUpdate"}, {"$set" : {"Account.Email" : "new@email.com"} });
    

    As you don’t need the AccountID and DeviceID to join anymore, you can also drop these two fields.

    Frequent updates

    When you have frequent updates, instead of embedding, you could use References. I think you have to resolve them client-side. You then have three collections:

    Account:

    {
      _id,
      UserName,
      Email
    }
    

    Device:

    {
      _id,
      DeviceCode
    }
    

    Association:

    {
      _id,
      account : {
            "$ref" : "Account",
            "$id" : ... }
      device : {
            "$ref" : "Device",
            "$id" : ... }
    }
    

    You don’t have any duplication this way, but you have to deal with references.

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

Sidebar

Related Questions

I have a rather large (many gigabytes) table of data in SQL Server that
I have a table that contains many rows of SQL commands that make up
I have a table in SQL that links to itself through parentID. I want
I have a table in SQL server that has the normal tree structure of
I have a History Table in SQL Server that basically tracks an item through
I have a table on SQL Server 2005 that was about 4gb in size.
Hi there I have an SQL table that looks like this: CREATE TABLE IF
I have a MS SQL table that I don't have any control over and
Ok I have a table in my SQL Server database that stores comments. My
I have a sql table of payroll data that has wage rates and effective

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.