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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:32:36+00:00 2026-05-28T16:32:36+00:00

I am trying to replicate what would be a left join in MySql in

  • 0

I am trying to replicate what would be a left join in MySql in Mongo. I have a collection named Clients and another collection name Orders.

In the clients collection is have:

client_PK, FirstName, LastName, Company

In the orders collection I have:

order_PK, client_fk, OrderDate, OrderAmount,  

So i know that can use embedded documents but for the sake of this question i am looking to use the reference model.

My question is, using these two collections how would I construct a table or object similar to a left join in mysql? I know this is a document db not a relational db but im using sql language just to give you an idea of what im trying to accomplish. In MySql it would look like this:

SELECT * FROM orders LEFT JOIN clients ON clients.client_PK = orders.client_fk

with this i could now construct a table that looked like:

FirstName | LastName | Company | OrderDate | OrderAmount

then i could repeat the rows using a while loop to display all orders and display the clients name with the order. Again i know mongo isn’t a relational db but i am assuming there is a way simulate a table using two collections.

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-05-28T16:32:37+00:00Added an answer on May 28, 2026 at 4:32 pm

    You almost certainly want to be storing these data all in the same MongoCollection (even in just a denormalization collection).

    If you absolutely can’t do that, though, and if your set is small, you can do something similar to this (since you asked about PHP):

    <?php
    // gather orders
    $orders = iterator_to_array($mongodb->orders->find());
    $joinedOrders = array();
    // gather clients
    foreach ($db->clients->find() as $client) {
        // iterate orders (like a left join)
        foreach ($orders as $order) {
            // make a "joinedOrders" record for each join match
            if ($order['client_fk'] == $client['client_PK']) {
                $joinedOrders[] = array_merge($order, $client);
            }
        }
    }
    // result is now in $joinedOrders
    

    This is, however, almost always a bad idea. (-: You really should be denormalizing your data, or using a relational database to store/query relational data.

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

Sidebar

Related Questions

Im trying to replicate an effect as seen on http://www.fiat.co.uk/Showroom/#showroom/punto_evo/explore . I have made
So I am trying to replicate Facebook's picture tagging functionality, and I have the
I have been trying to replicate the buffer overflow example3 from this article aleph
I'm trying to replicate a UI effect as on http://mcfc.co.uk I have written a
I have a simple question. I am trying to replicate the setup a colleague
Trying to replicate the docking controls in Visual Studio 2008. My application replays the
I'm trying to replicate a UI like a gcalendar (only the layout not any
I am trying to replicate the text overlay effect that occurs when you mouse
I am trying to replicate TryParse for generic types and thought that TypeDescriptor might
Basically I'm trying to replicate YouTube's ability to begin video playback from any part

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.