summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharlie Swanson <cswanson310@gmail.com>2016-10-13 16:50:50 -0400
committerCharlie Swanson <cswanson310@gmail.com>2016-10-14 11:21:15 -0400
commit978a2ba232297c9f10320e980a3f1a9f2f280462 (patch)
tree6330c85be3156ca48c10199636929b2432e37a74
parent805b4bdc9473ad1841fca738ebed80c7b2047a84 (diff)
downloadmongo-978a2ba232297c9f10320e980a3f1a9f2f280462.tar.gz
SERVER-26090 Propagate aggregate options through view resolution.
Ensures that the 'allowDiskUse' and 'bypassDocumentValidation' options are correctly translated after resolving a view.
-rw-r--r--jstests/views/views_aggregation.js43
-rw-r--r--src/mongo/db/views/resolved_view.cpp11
2 files changed, 53 insertions, 1 deletions
diff --git a/jstests/views/views_aggregation.js b/jstests/views/views_aggregation.js
index 87cf3d7908e..5a9c010be43 100644
--- a/jstests/views/views_aggregation.js
+++ b/jstests/views/views_aggregation.js
@@ -160,4 +160,47 @@
coll.getName(),
[{$facet: {nested: graphLookupPipeline}}],
[{nested: [{_id: "New York", matchedId1: "New York", matchedId2: "New York"}]}]);
+
+ // Test that an aggregate on a view propagates the 'bypassDocumentValidation' option.
+ const validatedCollName = "collectionWithValidator";
+ viewsDB[validatedCollName].drop();
+ assert.commandWorked(
+ viewsDB.createCollection(validatedCollName, {validator: {illegalField: {$exists: false}}}));
+
+ viewsDB.invalidDocs.drop();
+ viewsDB.invalidDocsView.drop();
+ assert.writeOK(viewsDB.invalidDocs.insert({illegalField: "present"}));
+ assert.commandWorked(viewsDB.createView("invalidDocsView", "invalidDocs", []));
+
+ assert.commandWorked(
+ viewsDB.runCommand({
+ aggregate: "invalidDocsView",
+ pipeline: [{$out: validatedCollName}],
+ bypassDocumentValidation: true
+ }),
+ "Expected $out insertions to succeed since 'bypassDocumentValidation' was specified");
+
+ // Test that an aggregate on a view propagates the 'allowDiskUse' option.
+ const extSortLimit = 100 * 1024 * 1024;
+ const largeStrSize = 10 * 1024 * 1024;
+ const largeStr = new Array(largeStrSize).join('x');
+ viewsDB.largeColl.drop();
+ for (let i = 0; i <= extSortLimit / largeStrSize; ++i) {
+ assert.writeOK(viewsDB.largeColl.insert({x: i, largeStr: largeStr}));
+ }
+ assertErrorCode(viewsDB.largeColl,
+ [{$sort: {x: -1}}],
+ 16819,
+ "Expected in-memory sort to fail due to excessive memory usage");
+ viewsDB.largeView.drop();
+ assert.commandWorked(viewsDB.createView("largeView", "largeColl", []));
+ assertErrorCode(viewsDB.largeView,
+ [{$sort: {x: -1}}],
+ 16819,
+ "Expected in-memory sort to fail due to excessive memory usage");
+
+ assert.commandWorked(
+ viewsDB.runCommand(
+ {aggregate: "largeView", pipeline: [{$sort: {x: -1}}], allowDiskUse: true}),
+ "Expected aggregate to succeed since 'allowDiskUse' was specified");
}());
diff --git a/src/mongo/db/views/resolved_view.cpp b/src/mongo/db/views/resolved_view.cpp
index 9ef966d3f61..b11db8958d2 100644
--- a/src/mongo/db/views/resolved_view.cpp
+++ b/src/mongo/db/views/resolved_view.cpp
@@ -92,8 +92,17 @@ StatusWith<BSONObj> ResolvedView::asExpandedViewAggregation(
aggregationBuilder.append("cursor", BSONObj());
}
- if (request.isExplain())
+ if (request.isExplain()) {
aggregationBuilder.append("explain", true);
+ }
+
+ if (request.shouldBypassDocumentValidation()) {
+ aggregationBuilder.append("bypassDocumentValidation", true);
+ }
+
+ if (request.shouldAllowDiskUse()) {
+ aggregationBuilder.append("allowDiskUse", true);
+ }
return aggregationBuilder.obj();
}