diff options
author | Charlie Swanson <charlie.swanson@mongodb.com> | 2021-10-05 00:35:26 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-10-05 00:48:06 +0000 |
commit | bd574911e9d1686922476938920516c37f9083f9 (patch) | |
tree | e77057581b2b0fd6c065d0429506fbeb6a087e3a /jstests/aggregation | |
parent | 6940a21899491ade7aab2fb95bfffc7fcd8d2e5c (diff) | |
download | mongo-bd574911e9d1686922476938920516c37f9083f9.tar.gz |
SERVER-60406 Harden $searchMeta implementation in unsharded collection
Diffstat (limited to 'jstests/aggregation')
-rw-r--r-- | jstests/aggregation/documents.js | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/jstests/aggregation/documents.js b/jstests/aggregation/documents.js index f9289a3baf0..5996b5dd4ff 100644 --- a/jstests/aggregation/documents.js +++ b/jstests/aggregation/documents.js @@ -29,7 +29,7 @@ coll.drop(writeConcernOptions); coll.insert({a: 1}, writeConcernOptions); // $documents given an array of objects. -const docs = coll.aggregate([{$documents: [{a1: 1}, {a1: 2}]}], writeConcernOptions).toArray(); +const docs = currDB.aggregate([{$documents: [{a1: 1}, {a1: 2}]}], writeConcernOptions).toArray(); assert.eq(2, docs.length); assert.eq(docs[0], {a1: 1}); @@ -37,7 +37,8 @@ assert.eq(docs[1], {a1: 2}); // $documents evaluates to an array of objects. const docs1 = - coll.aggregate([{$documents: {$map: {input: {$range: [0, 100]}, in : {x: "$$this"}}}}], + currDB + .aggregate([{$documents: {$map: {input: {$range: [0, 100]}, in : {x: "$$this"}}}}], writeConcernOptions) .toArray(); @@ -48,7 +49,8 @@ for (let i = 0; i < 100; i++) { // $documents evaluates to an array of objects. const docsUnionWith = - coll.aggregate( + currDB + .aggregate( [ {$documents: [{a: 13}]}, { @@ -76,9 +78,9 @@ assert.eq(res[0]["a"], 1); assert.eq(res[1], {xx: 1}); assert.eq(res[2], {xx: 2}); -function assertFails(pipeline, code) { +function assertFails(coll, pipeline, code) { assert.commandFailedWithCode(currDB.runCommand({ - aggregate: coll.getName(), + aggregate: coll, pipeline: pipeline, writeConcern: writeConcernOptions.writeConcern, cursor: {} @@ -87,16 +89,16 @@ function assertFails(pipeline, code) { } // Must fail due to misplaced $document. -assertFails([{$project: {a: [{xx: 1}, {xx: 2}]}}, {$documents: [{a: 1}]}], 40602); +assertFails(coll.getName(), [{$project: {a: [{xx: 1}, {xx: 2}]}}, {$documents: [{a: 1}]}], 40602); // $unionWith must fail due to no $document -assertFails([{$unionWith: {pipeline: [{$project: {a: [{xx: 1}, {xx: 2}]}}]}}], 9); +assertFails(coll.getName(), [{$unionWith: {pipeline: [{$project: {a: [{xx: 1}, {xx: 2}]}}]}}], 9); // Must fail due to $documents producing array of non-objects. -assertFails([{$documents: [1, 2, 3]}], 40228); +assertFails(1, [{$documents: [1, 2, 3]}], 40228); // Must fail due $documents producing non-array. -assertFails([{$documents: {a: 1}}], 5858203); +assertFails(1, [{$documents: {a: 1}}], 5858203); // Must fail due $documents producing array of non-objects. -assertFails([{$documents: {a: [1, 2, 3]}}], 5858203); +assertFails(1, [{$documents: {a: [1, 2, 3]}}], 5858203); })(); |