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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:53:08+00:00 2026-05-27T14:53:08+00:00

I’m trying to break down my RDBMS mentality with Mongoose in a node.js app,

  • 0

I’m trying to break down my RDBMS mentality with Mongoose in a node.js app, and could use some guidance as to best practices.

A simple example: Let’s say there are two collections, organizations and contacts. It’s a one-to-many relationship and they both need to be lonely. In an index method, however, I want to return an array of organization objects, each with an array of member contact objects. (And later I want to return an array of contacts, each with an organization object.)

It seems to me that I’m misunderstanding the best way to accomplish this. Here are the options as I see them thus far:

  1. Embed contacts with their ids in the organization documents. The index query could then be Organization.find({}, function(err, orgs) { orgs[n].contacts[n]...}).
    Disadvantage: Lots of extra storage necessary, and have to update embedded contact documents any time you change the “master” contact document.

  2. Take advantage of Mongoose’s populate/DBRef structure to store “foreign key” ids in both tables. The query can then be: Organization.find({}}.populate('contacts').run(...).
    Disadvantage: You have to store keys on both sides.

  3. Go the more traditional “foreign key” route, storing just the organization id in a contact document. Query the organization documents and then query all the contacts in the organization query’s callback, combining the data into one object to return.
    Disadvantage: Multiple queries and extra processing overhead (I believe we have to find the orgs and contacts for those orgs independently and then iterate back over each, matching manually on the common _id field, to combine them into a new output object).

I must be missing a better option. Something that allows for the schema of #3 but returns the desired combined object with much less overhead.

NOTE: The async module seems like it could help with this, but is this really the only/best 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-27T14:53:08+00:00Added an answer on May 27, 2026 at 2:53 pm

    This really depends on the queries you are going to make.
    – Does your site depend more on contacts or on organizations?
    – Will you often need to display all contacts from an organization?
    – What details for contacts do you need to display on an organization page?

    Etc.

    So this really depends on your project’s needs. Are you organizations and contacts page constantly being updated? If not than duplicating data doesn’t seem such a bad idea, especially if your site is more read heavy.

    Bottom line: think on what pages you’ll have on the site and what will that pages need to display (thus what queries would need to be made).

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.