---
title: "How to Join Collections in MongoDB Using $lookup Aggregation?"  
description: "How to Join Collections in MongoDB Using $lookup Aggregation?"  
author: "Lily Chitlangiya"  
published: 2026-09-01  
updated: 2026-09-01  
canonical: https://answers.mindstick.com/qa/117130/how-to-join-collections-in-mongodb-using-lookup-aggregation  
category: "MongoDB"  
tags: ["mongodb", "aggregation", "database-joins", "NoSQL"]  
reading_time: 1 minute  

---

# How to Join Collections in MongoDB Using $lookup Aggregation?

Coming from a relational database background, I need to query related documents stored in separate collections. How does the `$lookup` operator work in MongoDB's aggregation pipeline to join two collections?

## Understanding $lookup

The `$lookup` stage performs a left outer join to an unsharded collection in the same database, filtering in documents from the joined collection for processing.

- **localField:** The field from the input documents passed into the `$lookup` stage.
- **foreignField:** The field from the documents in the target collection.
- **as:** The name of the new array field added to input documents containing matches.

### Example Aggregation Pipeline

```
db.orders.aggregate([
    {
        $lookup: {
            from: "products",
            localField: "productId",
            foreignField: "_id",
            as: "productDetails"
        }
    }
]);
```


---

Original Source: https://answers.mindstick.com/qa/117130/how-to-join-collections-in-mongodb-using-lookup-aggregation

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
