diff options
Diffstat (limited to 'jstests/aggregation/sources/graphLookup/basic.js')
-rw-r--r-- | jstests/aggregation/sources/graphLookup/basic.js | 148 |
1 files changed, 81 insertions, 67 deletions
diff --git a/jstests/aggregation/sources/graphLookup/basic.js b/jstests/aggregation/sources/graphLookup/basic.js index 8ee26a64f9f..15c8ef85e22 100644 --- a/jstests/aggregation/sources/graphLookup/basic.js +++ b/jstests/aggregation/sources/graphLookup/basic.js @@ -19,59 +19,67 @@ assert.writeOK(local.insert({starting: 50})); // Perform a simple $graphLookup and ensure it retrieves every result. - var res = local.aggregate({ - $graphLookup: { - from: "foreign", - startWith: "$starting", - connectFromField: "neighbors", - connectToField: "_id", - as: "integers" - } - }).toArray()[0]; + var res = local + .aggregate({ + $graphLookup: { + from: "foreign", + startWith: "$starting", + connectFromField: "neighbors", + connectToField: "_id", + as: "integers" + } + }) + .toArray()[0]; assert.eq(res.integers.length, 100); // Perform a $graphLookup and ensure it respects "maxDepth". - res = local.aggregate({ - $graphLookup: { - from: "foreign", - startWith: "$starting", - connectFromField: "neighbors", - connectToField: "_id", - maxDepth: 5, - as: "integers" - } - }).toArray()[0]; + res = local + .aggregate({ + $graphLookup: { + from: "foreign", + startWith: "$starting", + connectFromField: "neighbors", + connectToField: "_id", + maxDepth: 5, + as: "integers" + } + }) + .toArray()[0]; // At depth zero, we retrieve one integer, and two for every depth thereafter. assert.eq(res.integers.length, 11); // Perform a $graphLookup and ensure it properly evaluates "startWith". - res = local.aggregate({ - $graphLookup: { - from: "foreign", - startWith: {$add: ["$starting", 3]}, - connectFromField: "neighbors", - connectToField: "_id", - maxDepth: 0, - as: "integers" - } - }).toArray()[0]; + res = local + .aggregate({ + $graphLookup: { + from: "foreign", + startWith: {$add: ["$starting", 3]}, + connectFromField: "neighbors", + connectToField: "_id", + maxDepth: 0, + as: "integers" + } + }) + .toArray()[0]; assert.eq(res.integers.length, 1); assert.eq(res.integers[0]._id, 53); // Perform a $graphLookup and ensure it properly expands "startWith". - res = local.aggregate({ - $graphLookup: { - from: "foreign", - startWith: {$literal: [1, 2, 3]}, - connectFromField: "neighbors", - connectToField: "_id", - maxDepth: 0, - as: "integers" - } - }).toArray()[0]; + res = local + .aggregate({ + $graphLookup: { + from: "foreign", + startWith: {$literal: [1, 2, 3]}, + connectFromField: "neighbors", + connectToField: "_id", + maxDepth: 0, + as: "integers" + } + }) + .toArray()[0]; assert.eq(res.integers.length, 3); @@ -83,15 +91,17 @@ assert.writeOK(foreign.insert({_id: 51})); assert.writeOK(foreign.insert({_id: null, neighbors: [50, 52]})); - res = local.aggregate({ - $graphLookup: { - from: "foreign", - startWith: "$starting", - connectFromField: "neighbors", - connectToField: "_id", - as: "integers" - } - }).toArray()[0]; + res = local + .aggregate({ + $graphLookup: { + from: "foreign", + startWith: "$starting", + connectFromField: "neighbors", + connectToField: "_id", + as: "integers" + } + }) + .toArray()[0]; // Our result should be missing the values with _id from 52 to 99. assert.eq(res.integers.length, 52); @@ -103,29 +113,33 @@ assert.writeOK(foreign.update({_id: 99}, {$set: {neighbors: [98, 0]}})); assert.writeOK(foreign.update({_id: 0}, {$set: {neighbors: [99, 1]}})); - res = local.aggregate({ - $graphLookup: { - from: "foreign", - startWith: "$starting", - connectFromField: "neighbors", - connectToField: "_id", - as: "integers" - } - }).toArray()[0]; + res = local + .aggregate({ + $graphLookup: { + from: "foreign", + startWith: "$starting", + connectFromField: "neighbors", + connectToField: "_id", + as: "integers" + } + }) + .toArray()[0]; assert.eq(res.integers.length, 100); // Perform a $graphLookup and ensure that "depthField" is properly populated. - res = local.aggregate({ - $graphLookup: { - from: "foreign", - startWith: "$starting", - connectFromField: "neighbors", - connectToField: "_id", - depthField: "distance", - as: "integers" - } - }).toArray()[0]; + res = local + .aggregate({ + $graphLookup: { + from: "foreign", + startWith: "$starting", + connectFromField: "neighbors", + connectToField: "_id", + depthField: "distance", + as: "integers" + } + }) + .toArray()[0]; assert.eq(res.integers.length, 100); |