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

  • Home
  • SEARCH
  • 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 9141387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:38:17+00:00 2026-06-17T09:38:17+00:00

I coming from a sql background so writing queries in sql where I join

  • 0

I coming from a sql background so writing queries in sql where I join tables is quite simple but I guess I am missing that in mongoose/mongodb

Basically I know the Subscriber_ID (which maps to a document in the User Collection)

I want to pull the project group, with all the projects that the user belongs to so if I was to write this in pseduo sql it would be like

Select 
  ProjectGroup.title, 
  Project.Title 
FROM 
  ProjectGroup, 
  Project, 
  User 
WHERE 
  User.id = req.body.subscriber_id 
  AND Project.subscriber_id = User.id 
  AND  ProjectGroup.project_id = Project.id

There must be a way to do similiar joins in mongoose/mongodb because the type is mapping to a schema right?

My Schemas…..

Project Group Schema

var ProjectGroupSchema = new Schema({
    title             : String
  , projects          : [ { type: Schema.Types.ObjectId, ref: 'Project' } ]
});

Project Schema

var ProjectSchema = new Schema({
    title         : {type : String, default : '', required : true}
  , subscribers   : [{ type: Schema.Types.ObjectId, ref: 'User' }]
});

User Schema

var UserSchema = new Schema({
    first_name    : {type: String, required: true}
  , last_name     : {type: String, required: true}
});

Thank you!

  • 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-17T09:38:18+00:00Added an answer on June 17, 2026 at 9:38 am

    You are just one step away!

    Project Group Schema:

    var ProjectGroupSchema = new Schema({
        title             : String
    });
    

    Project Schema:

    var ProjectSchema = new Schema({
        title         : {type : String, default : '', required : true},
        group         : {type: Schema.Types.ObjectId, ref: 'ProjectGroup' },
        _users    : [{type: Schema.Types.ObjectId, ref: 'User' }]
    });
    

    User Schema:

    var UserSchema = new Schema({
        first_name    : {type: String, required: true},
        last_name     : {type: String, required: true},
        subscribing   : [{type: Schema.Types.ObjectId, ref: 'Project' }]
    });
    

    Then you can do the following:

    user.findById(req.userId)
         .populate('subscribing')
         .exec(function(err, user){
              console.log(user.subscribing);
         })
    

    Or:

    project.find({
            subscriber : req.userId
          })
         .populate('subscriber')
         .populate('group')
         .exec(function(err, projects){
              console.log(projects);
         })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Coming from a PHP background, I'm used to writing small functions that return a
I'm coming from PHP background. When composing SQL queries I tend to do something
I'm coming from a MS SQL Server background. Working on a new project using
Im a bit new to T-SQL, Coming from a MySQL background Im still adapting
I have an array coming from a SQL query that follows the following format:
Below is a Class that converts a string (coming from a sql server database)
Coming from a non-SQL background, I've been having a hard time absorbing SQLite3 for
I'm coming from a SQL Server background. What would the equivalent data types be
I have discovered that results coming from my SQL Server are having the field
I am coming from a SQL server 2008 background. I have a mysql local

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.