@@ -336,25 +336,30 @@ Across Multiple Collections
336
336
Like :pipeline:`$lookup`, :pipeline:`$graphLookup` can access
337
337
another collection in the same database.
338
338
339
- In the following example, a database contains two collections:
339
+ For example, create a database with two collections:
340
340
341
- - A collection ``airports`` with the following documents:
341
+ - An ``airports`` collection with the following documents:
342
342
343
343
.. code-block:: javascript
344
344
345
- { "_id" : 0, "airport" : "JFK", "connects" : [ "BOS", "ORD" ] }
346
- { "_id" : 1, "airport" : "BOS", "connects" : [ "JFK", "PWM" ] }
347
- { "_id" : 2, "airport" : "ORD", "connects" : [ "JFK" ] }
348
- { "_id" : 3, "airport" : "PWM", "connects" : [ "BOS", "LHR" ] }
349
- { "_id" : 4, "airport" : "LHR", "connects" : [ "PWM" ] }
345
+ db.airports.insertMany( [
346
+ { "_id" : 0, "airport" : "JFK", "connects" : [ "BOS", "ORD" ] },
347
+ { "_id" : 1, "airport" : "BOS", "connects" : [ "JFK", "PWM" ] },
348
+ { "_id" : 2, "airport" : "ORD", "connects" : [ "JFK" ] },
349
+ { "_id" : 3, "airport" : "PWM", "connects" : [ "BOS", "LHR" ] },
350
+ { "_id" : 4, "airport" : "LHR", "connects" : [ "PWM" ] }
351
+ ] )
350
352
351
- - A collection ``travelers`` with the following documents:
353
+ - A ``travelers`` collection with the following documents:
352
354
353
355
.. code-block:: javascript
354
356
355
- { "_id" : 1, "name" : "Dev", "nearestAirport" : "JFK" }
356
- { "_id" : 2, "name" : "Eliot", "nearestAirport" : "JFK" }
357
- { "_id" : 3, "name" : "Jeff", "nearestAirport" : "BOS" }
357
+ db.travelers.insertMany( [
358
+ { "_id" : 1, "name" : "Dev", "nearestAirport" : "JFK" },
359
+ { "_id" : 2, "name" : "Eliot", "nearestAirport" : "JFK" },
360
+ { "_id" : 3, "name" : "Jeff", "nearestAirport" : "BOS" }
361
+ ] )
362
+
358
363
359
364
For each document in the ``travelers`` collection, the following
360
365
aggregation operation looks up the ``nearestAirport`` value in the
0 commit comments