Cartesian product (CROSS JOIN) in MongoDB

📰 Dev.to · Franck Pachot

Learn to perform a Cartesian product, equivalent to a CROSS JOIN in relational databases, in MongoDB to combine all documents from two collections

intermediate Published 14 Feb 2026
Action Steps
  1. Understand the concept of Cartesian product and its relation to CROSS JOIN in relational databases
  2. Use the $lookup operator in MongoDB to perform an unordered Cartesian product
  3. Apply the $unwind operator to flatten the resulting array
  4. Filter the results using the $match operator to narrow down the data
  5. Test the query using the MongoDB shell or a driver to verify the results
Who Needs to Know This

Developers and data engineers working with MongoDB can benefit from this technique to combine data from multiple collections, useful for data analysis and reporting

Key Insight

💡 The $lookup operator in MongoDB can be used to perform an unordered Cartesian product, similar to a CROSS JOIN in relational databases

Share This
📊 Perform a Cartesian product in MongoDB using $lookup and $unwind operators #MongoDB #CROSSJOIN

Key Takeaways

Learn to perform a Cartesian product, equivalent to a CROSS JOIN in relational databases, in MongoDB to combine all documents from two collections

Full Article

Relational database joins are, conceptually, a cartesian product followed by a filter (the join...
Read full article → ← Back to Reads