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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:09:50+00:00 2026-06-17T22:09:50+00:00

I want to store carpool_debts which is basically going to hold the number of

  • 0

I want to store “carpool_debts” which is basically going to hold the number of days owed to other users. It looks like this:

carpool_debts{
              _id,
              owner,
              owner_id,
              creditors:[{name,
                          id,
                          amount},
                          {name,
                           id,
                           amount}
                        ]} 

Does that data structure look reasonable for what I want to store? Also implementing that data structure seemed cumbersome to maintain. I found it cumbersome mainly because there isn’t an upsert type of function available in meteor yet. Instead of creditors being a list of sub documents would I be better off storing the creditors as a delimited string? I would like to know if I am on the right path or if I am missing something? Thanks.

  • 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-06-17T22:09:51+00:00Added an answer on June 17, 2026 at 10:09 pm

    You can structure mongo documents just like you would in a relational database, for example, having separate collections for creditors and owners and using carpool_debts as a link table with the amount attached:

    carpool_debts{
                  _id,
                  owner_id,
                  creditor_id,
                  amount}
    
    creditors{
              _id,
              name}
    
    owners{
           _id,
           name}
    

    However, this is not using mongodb to its full potential. Especially if this is a database with masses of data, you may want to optimise it for the most used queries, otherwise it’ll be slow. For example, to optimise for looking up an owner’s debt, you can add the data needed right there in the owners collection, using sub documents for creditors, and sub documents again for individual debts, similar to what you’ve already done:

    owners{
           _id,
           name,
           creditors: {id,
                       name,
                       debts: {
                               amount,
                               due_date}
                      }
          }
    

    and similarly, add the debt information on the creditors collection if you often look up the outstanding debt of creditors:

    creditors{
              _id,
              name,
              debtors: {
                        owner_id,
                        owner_name, 
                        debts: { 
                                 aount,
                                 due_date
                               }
                       }
             }
    

    This way, you only need to look up one record to get all the information you need. Of course, there are catches. First of all, this is not very DRY, but that’s intentional. But you have to remember to update the other table(s) when something changes. If you change the name of a creditor for example, you’ll need to update every owner document that has debts with this creditor (make sure you index that). This of course makes updates much slower (and the database bigger), but if you don’t update very often, and look up much more often, this is not going to be a problem.
    Also if for example creditors can have thousands of individual outstanding debts, you may have to separate that into a link table, or rather, link collection, like this, so you don’t exceed mongodb’s maximum document size:

    creditors{
              _id,
              name,
             }
    
    debtors: {
               owner_id,
               creditor_id, 
               debts: { 
                        amount,
                        due_date
                      }
              }
    

    Then you have one document for each creditor-owner connection. This means more documents to look up when looking at a creditor, but still just one for looking up an owner.

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

Sidebar

Related Questions

I want to store ids in database like this 1,2,3,4,5 in one field from
I want to store user-clicked data in a cookie which never has to go
I have this code: I want to store some vales in a day of
I want to store the current page number in a jquery variable, but I
I want to store some genomic positions (chromosome,position) using MongoDB. something like: { chrom:chr2,
I want to store which user invited another user to a group... but django
I want to store videos, images and long text in SQL Server 2005. Which
I want to store large number of videos in my application's directory. Will it
I want store a list of doubles and ints to a ByteBuffer, which asks
I want store a number as a global variable. What syntax do I use,

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.