From the course: MongoDB Essential Training
Unlock the full course today
Join today to access over 24,100 courses taught by industry experts.
$lookup - MongoDB Tutorial
From the course: MongoDB Essential Training
$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
-
-
-
-
-
-
-
An overview of stages1m 47s
-
(Locked)
$group4m 14s
-
(Locked)
$bucket5m 15s
-
(Locked)
$unwind3m 18s
-
(Locked)
$merge and $out3m 59s
-
(Locked)
$function3m 27s
-
(Locked)
$lookup4m 44s
-
(Locked)
Performance10m 38s
-
(Locked)
Challenge: Write aggregation pipelines24s
-
(Locked)
Solution: Write aggregation pipelines5m 18s
-
-
-
-