diff options
Diffstat (limited to 'jstests/aggregation/sources/graphLookup/airports.js')
-rw-r--r-- | jstests/aggregation/sources/graphLookup/airports.js | 78 |
1 files changed, 37 insertions, 41 deletions
diff --git a/jstests/aggregation/sources/graphLookup/airports.js b/jstests/aggregation/sources/graphLookup/airports.js index 7cf0142c631..71a38e268b8 100644 --- a/jstests/aggregation/sources/graphLookup/airports.js +++ b/jstests/aggregation/sources/graphLookup/airports.js @@ -30,45 +30,39 @@ local.insert({}); // Perform a simple $graphLookup and ensure it retrieves every result. - var res = local.aggregate({ - $graphLookup: { - from: "foreign", - startWith: "PWM", - connectFromField: "connects", - connectToField: "_id", - as: "connections" - } - }).toArray()[0]; - - // "foreign" represents a connected graph. - assert.eq(res.connections.length, airports.length); - - // Perform a $graphLookup and ensure it correctly computes the shortest path to a node when more - // than one path exists. - res = local.aggregate( - { + var res = local + .aggregate({ $graphLookup: { from: "foreign", - startWith: "BOS", + startWith: "PWM", connectFromField: "connects", connectToField: "_id", - depthField: "hops", as: "connections" } - }, - {$unwind: "$connections"}, - {$project: {_id: "$connections._id", hops: "$connections.hops"}}).toArray(); + }) + .toArray()[0]; + + // "foreign" represents a connected graph. + assert.eq(res.connections.length, airports.length); + + // Perform a $graphLookup and ensure it correctly computes the shortest path to a node when more + // than one path exists. + res = local + .aggregate({ + $graphLookup: { + from: "foreign", + startWith: "BOS", + connectFromField: "connects", + connectToField: "_id", + depthField: "hops", + as: "connections" + } + }, + {$unwind: "$connections"}, + {$project: {_id: "$connections._id", hops: "$connections.hops"}}) + .toArray(); - var expectedDistances = { - BOS: 0, - PWM: 1, - JFK: 1, - LGA: 1, - ORD: 2, - SFO: 2, - MIA: 3, - ATL: 4 - }; + var expectedDistances = {BOS: 0, PWM: 1, JFK: 1, LGA: 1, ORD: 2, SFO: 2, MIA: 3, ATL: 4}; assert.eq(res.length, airports.length); res.forEach(function(c) { @@ -78,15 +72,17 @@ // Disconnect the graph, and ensure we don't find the other side. foreign.remove({_id: "JFK"}); - res = db.local.aggregate({ - $graphLookup: { - from: "foreign", - startWith: "ATL", - connectFromField: "connects", - connectToField: "_id", - as: "connections" - } - }).toArray()[0]; + res = db.local + .aggregate({ + $graphLookup: { + from: "foreign", + startWith: "ATL", + connectFromField: "connects", + connectToField: "_id", + as: "connections" + } + }) + .toArray()[0]; // ATL should now connect to itself, MIA, and SFO. assert.eq(res.connections.length, 3); |