Skip to content

Instantly share code, notes, and snippets.

@parkerfoshay
Created November 23, 2022 21:07
Show Gist options
  • Save parkerfoshay/7cd9d50dd43b0660a55185a24429e898 to your computer and use it in GitHub Desktop.
Save parkerfoshay/7cd9d50dd43b0660a55185a24429e898 to your computer and use it in GitHub Desktop.
Joins
db.transfers.aggregate( [
{
$lookup:
{
from: "accounts",
localField: "transfer_id",
foreignField: "transfers_complete",
pipeline: [
{ $project: { _id: 0, account_id: 1, account_holder: 1 } }
],
as: "account_holder"
}
}
] )
SELECT *, account_holder
FROM transfers
WHERE inventory_docs IN (
SELECT account_holder, account_id
FROM accounts
WHERE transferss_complete = transfers.transfer_id
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment