From the course: MongoDB Essential Training

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

$lookup

$lookup

- [Instructor] The $lookup stage allows you to perform joins. That is to pull in data from another collection based on a matching field. In this example, we have an order document, which contains a car ID and some other order information, and we have an inventory document, which contains the same car ID and information about the car. The $lookup command allows you to merge information from both documents by matching the car ID field. Of course, this would not only happen for one order document, but for all orders. Let's look at it in code. All right, so I'm going to be using the orders collection to show off how the $lookup stage works. And of course, we are going to use the aggregate method again because $lookup is an aggregation stage. The aggregate method takes an array as its argument. And inside the argument, we are going to have just one document for the one lookup stage. So here we are going to use the $lookup…

Contents