summaryrefslogtreecommitdiff
path: root/jstests/aggregation/bugs/server6127.js
diff options
context:
space:
mode:
authorKyle Suarez <kyle.suarez@mongodb.com>2017-12-14 14:09:13 -0500
committerKyle Suarez <kyle.suarez@mongodb.com>2017-12-14 14:13:26 -0500
commit47247293f18ea581954f6fcf4c0018b7828e3c3a (patch)
treecd5572f377474ecf35baaaf8c4e194d66611a860 /jstests/aggregation/bugs/server6127.js
parentf4c11f679de3781ae202511fe07144e357c80e2b (diff)
downloadmongo-47247293f18ea581954f6fcf4c0018b7828e3c3a.tar.gz
SERVER-31785 use multiple shards in aggregation_sharded_collections_passthrough
Diffstat (limited to 'jstests/aggregation/bugs/server6127.js')
-rw-r--r--jstests/aggregation/bugs/server6127.js57
1 files changed, 20 insertions, 37 deletions
diff --git a/jstests/aggregation/bugs/server6127.js b/jstests/aggregation/bugs/server6127.js
index f217e9a8d93..26585c87d21 100644
--- a/jstests/aggregation/bugs/server6127.js
+++ b/jstests/aggregation/bugs/server6127.js
@@ -1,44 +1,27 @@
/*
- * SERVER-6127 : $project uasserts if an expected nested field has a non object parent in a document
+ * SERVER-6127 : $project uasserts if an expected nested field has a non object parent in a
+ * document.
*
* This test validates the SERVER-6127 ticket. Return undefined when retrieving a field along a
- * path, when the subpath does not exist (this is what happens when a field does not exist and
- * there is no path). Previous it would uassert causing the aggregation to end.
+ * path, when the subpath does not exist (this is what happens when a field does not exist and there
+ * is no path). Previous it would uassert causing the aggregation to end.
*/
+(function() {
+ "use strict";
+ db.s6127.drop();
-/*
- * 1) Clear and create testing db
- * 2) Run an aggregation that simply projects a two fields, one with a sub path one without
- * 3) Assert that the result is what we expected
- */
-
-// Clear db
-db.s6127.drop();
-
-// Populate db
-db.s6127.save({a: 1});
-db.s6127.save({foo: 2});
-db.s6127.save({foo: {bar: 3}});
-
-// Aggregate checking the field foo and the path foo.bar
-var s6127 = db.s6127.aggregate({$project: {_id: 0, 'foo.bar': 1, field: "$foo", path: "$foo.bar"}});
-
-/*
- * The first document should contain nothing as neither field exists, the second document should
- * contain only field as it has a value in foo, but foo does not have a field bar so it cannot walk
- * that path, the third document should have both the field and path as foo is an object which has
- * a field bar
- */
-var s6127result = [
- {},
- {field: 2},
- {
- foo: {bar: 3},
- field: {bar: 3},
- path: 3
+ assert.writeOK(db.s6127.insert({_id: 0, a: 1}));
+ assert.writeOK(db.s6127.insert({_id: 1, foo: 2}));
+ assert.writeOK(db.s6127.insert({_id: 2, foo: {bar: 3}}));
- }
-];
+ // Aggregate checking the field foo and the path foo.bar.
+ const cursor = db.s6127.aggregate(
+ [{$sort: {_id: 1}}, {$project: {_id: 0, "foo.bar": 1, field: "$foo", path: "$foo.bar"}}]);
-// Assert
-assert.eq(s6127.toArray(), s6127result, 's6127 failed');
+ // The first document should contain nothing as neither field exists, the second document should
+ // contain only field as it has a value in foo, but foo does not have a field bar so it cannot
+ // walk that path, the third document should have both the field and path as foo is an object
+ // which has a field bar.
+ const expected = [{}, {field: 2}, {foo: {bar: 3}, field: {bar: 3}, path: 3}];
+ assert.eq(cursor.toArray(), expected);
+}());