diff options
author | Nick Zolnierz <nicholas.zolnierz@mongodb.com> | 2018-08-09 10:30:34 -0400 |
---|---|---|
committer | Nick Zolnierz <nicholas.zolnierz@mongodb.com> | 2018-08-09 15:44:35 -0400 |
commit | fc758e567998b87a2360c1c49e3bd0b74da3796b (patch) | |
tree | b00df58371e8ad1973587173bd8ea3441295e94e /jstests | |
parent | c19c600b78d6176ace0044d2af0104e44c51610a (diff) | |
download | mongo-fc758e567998b87a2360c1c49e3bd0b74da3796b.tar.gz |
SERVER-36123: Reject $out with mode: replaceCollection if the output collection is sharded
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/core/views/views_aggregation.js | 2 | ||||
-rw-r--r-- | jstests/sharding/out_to_existing.js | 12 |
2 files changed, 9 insertions, 5 deletions
diff --git a/jstests/core/views/views_aggregation.js b/jstests/core/views/views_aggregation.js index 6175ccfe2bc..0ee368c4e24 100644 --- a/jstests/core/views/views_aggregation.js +++ b/jstests/core/views/views_aggregation.js @@ -74,7 +74,7 @@ assertAggResultEq("popSortedView", [{$limit: 1}, {$project: {_id: 1}}], [{_id: "Palo Alto"}]); // Test that the $out stage errors when given a view namespace. - assertErrorCode(coll, [{$out: "emptyPipelineView"}], 18631); + assertErrorCode(coll, [{$out: "emptyPipelineView"}], ErrorCodes.CommandNotSupportedOnView); // Test that an aggregate on a view propagates the 'bypassDocumentValidation' option. const validatedCollName = "collectionWithValidator"; diff --git a/jstests/sharding/out_to_existing.js b/jstests/sharding/out_to_existing.js index fe3e17fc9e5..82559b5e6d0 100644 --- a/jstests/sharding/out_to_existing.js +++ b/jstests/sharding/out_to_existing.js @@ -58,17 +58,21 @@ sourceColl.aggregate([{$out: {to: targetColl.getName(), mode: "insertDocuments"}}]); assert.eq(20, targetColl.find().itcount()); - // Test that mode "replaceCollection" will drop the target collection and replace with the - // contents of the $out. - // TODO SERVER-36123: Mode "replaceCollection" should fail (gracefully) if the target exists - // and is sharded. if (!shardedTarget) { + // Test that mode "replaceCollection" will drop the target collection and replace with + // the contents of the $out. sourceColl.aggregate([{$out: {to: targetColl.getName(), mode: "replaceCollection"}}]); assert.eq(10, targetColl.find().itcount()); // Legacy syntax should behave identical to mode "replaceCollection". sourceColl.aggregate([{$out: targetColl.getName()}]); assert.eq(10, targetColl.find().itcount()); + } else { + // Test that mode "replaceCollection" fails if the target collection is sharded. + assertErrorCode( + sourceColl, [{$out: {to: targetColl.getName(), mode: "replaceCollection"}}], 28769); + + assertErrorCode(sourceColl, [{$out: targetColl.getName()}], 28769); } } |