@@ -317,25 +317,30 @@ Across Multiple Collections
317
317
Like :pipeline:`$lookup`, :pipeline:`$graphLookup` can access
318
318
another collection in the same database.
319
319
320
- In the following example, a database contains two collections:
320
+ For example, create a database with two collections:
321
321
322
- - A collection ``airports`` with the following documents:
322
+ - An ``airports`` collection with the following documents:
323
323
324
324
.. code-block:: javascript
325
325
326
- { "_id" : 0, "airport" : "JFK", "connects" : [ "BOS", "ORD" ] }
327
- { "_id" : 1, "airport" : "BOS", "connects" : [ "JFK", "PWM" ] }
328
- { "_id" : 2, "airport" : "ORD", "connects" : [ "JFK" ] }
329
- { "_id" : 3, "airport" : "PWM", "connects" : [ "BOS", "LHR" ] }
330
- { "_id" : 4, "airport" : "LHR", "connects" : [ "PWM" ] }
326
+ db.airports.insertMany( [
327
+ { "_id" : 0, "airport" : "JFK", "connects" : [ "BOS", "ORD" ] },
328
+ { "_id" : 1, "airport" : "BOS", "connects" : [ "JFK", "PWM" ] },
329
+ { "_id" : 2, "airport" : "ORD", "connects" : [ "JFK" ] },
330
+ { "_id" : 3, "airport" : "PWM", "connects" : [ "BOS", "LHR" ] },
331
+ { "_id" : 4, "airport" : "LHR", "connects" : [ "PWM" ] }
332
+ ] )
331
333
332
- - A collection ``travelers`` with the following documents:
334
+ - A ``travelers`` collection with the following documents:
333
335
334
336
.. code-block:: javascript
335
337
336
- { "_id" : 1, "name" : "Dev", "nearestAirport" : "JFK" }
337
- { "_id" : 2, "name" : "Eliot", "nearestAirport" : "JFK" }
338
- { "_id" : 3, "name" : "Jeff", "nearestAirport" : "BOS" }
338
+ db.travelers.insertMany( [
339
+ { "_id" : 1, "name" : "Dev", "nearestAirport" : "JFK" },
340
+ { "_id" : 2, "name" : "Eliot", "nearestAirport" : "JFK" },
341
+ { "_id" : 3, "name" : "Jeff", "nearestAirport" : "BOS" }
342
+ ] )
343
+
339
344
340
345
For each document in the ``travelers`` collection, the following
341
346
aggregation operation looks up the ``nearestAirport`` value in the
0 commit comments