summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Reams <jbreams@mongodb.com>2015-11-09 10:35:12 -0500
committerJonathan Reams <jbreams@mongodb.com>2015-11-11 11:12:17 -0500
commit338f764be00c3a5cef387dd1ba8a56671fc4ef6b (patch)
tree361281c805e0230d5227d5c433d0b29bc6258693
parent17b1cdd81328e94c03d97860ec5688028e0f6c22 (diff)
downloadmongo-338f764be00c3a5cef387dd1ba8a56671fc4ef6b.tar.gz
SERVER-6102 Deserialize BSON undefined as JS undefined
-rw-r--r--jstests/aggregation/bugs/server4638.js2
-rw-r--r--jstests/core/group2.js7
-rw-r--r--jstests/tool/exportimport1.js14
-rw-r--r--src/mongo/dbtests/jstests.cpp9
-rw-r--r--src/mongo/scripting/mozjs/valuereader.cpp6
5 files changed, 12 insertions, 26 deletions
diff --git a/jstests/aggregation/bugs/server4638.js b/jstests/aggregation/bugs/server4638.js
index bb75aba99b2..a6689e8ca5b 100644
--- a/jstests/aggregation/bugs/server4638.js
+++ b/jstests/aggregation/bugs/server4638.js
@@ -14,5 +14,5 @@ assert.eq(res[0].x, 0);
// Make sure having an undefined doesn't break pipelines that do use the field
res = t.aggregate( { $project : { undef : 1 } } ).toArray();
assert.eq(res[0].undef, undefined);
-// assert.eq(typeof(res[0].undef), "undefined"); // Commented out due to SERVER-6102
+assert.eq(typeof(res[0].undef), "undefined");
diff --git a/jstests/core/group2.js b/jstests/core/group2.js
index a8e6653470a..c29f8459adb 100644
--- a/jstests/core/group2.js
+++ b/jstests/core/group2.js
@@ -23,16 +23,19 @@ assert.eq(1, result[0].count, "F");
assert.eq(1, result[1].count, "G");
assert.eq(1, result[2].count, "H");
+var keyFn = function(x) {
+ return { a: 'a' in x ? x.a : null };
+};
delete cmd.key
-cmd["$keyf"] = function(x){ return { a : x.a }; };
+cmd["$keyf"] = keyFn;
result2 = t.group( cmd );
assert.eq( result , result2, "check result2" );
delete cmd.$keyf
-cmd["keyf"] = function(x){ return { a : x.a }; };
+cmd["keyf"] = keyFn;
result3 = t.group( cmd );
assert.eq( result , result3, "check result3" );
diff --git a/jstests/tool/exportimport1.js b/jstests/tool/exportimport1.js
index a7a7bcee90c..451078e1b95 100644
--- a/jstests/tool/exportimport1.js
+++ b/jstests/tool/exportimport1.js
@@ -19,12 +19,7 @@ assert.eq( 1 , c.count() , "after restore 2" );
var doc = c.findOne();
assert.eq( 22 , doc.a , "after restore 2" );
for (var i=0; i<arr.length; i++) {
- if (typeof arr[i] == 'undefined') {
- // null should be { "$undefined" : true }, but this is a workaround for SERVER-6102
- assert.eq( null, doc.b[i] , "after restore array: "+i );
- } else {
- assert.eq( arr[i], doc.b[i] , "after restore array: "+i );
- }
+ assert.eq( arr[i], doc.b[i] , "after restore array: "+i );
}
// now with --jsonArray
@@ -54,12 +49,7 @@ assert.soon( "c.findOne()" , "no data after sleep" );
assert.eq( 1 , c.count() , "after restore 2" );
var doc = c.findOne();
for (var i=0; i<arr.length; i++) {
- if (typeof arr[i] == 'undefined') {
- // null should be { "$undefined" : true }, but this is a workaround for SERVER-6102
- assert.eq( null, doc.a[i] , "after restore array: "+i );
- } else {
- assert.eq( arr[i], doc.a[i] , "after restore array: "+i );
- }
+ assert.eq( arr[i], doc.a[i] , "after restore array: "+i );
}
diff --git a/src/mongo/dbtests/jstests.cpp b/src/mongo/dbtests/jstests.cpp
index fc043e01323..fee13dde315 100644
--- a/src/mongo/dbtests/jstests.cpp
+++ b/src/mongo/dbtests/jstests.cpp
@@ -1505,18 +1505,9 @@ class Undefined : public TestRoundTrip {
return b.obj();
}
- // Don't need to return anything because we are overriding both jsonOut and jsonIn
virtual string json() const {
- return "";
- }
-
- // undefined values come out as null in the shell. See SERVER-6102.
- virtual string jsonIn() const {
return "{ \"a\" : undefined }";
}
- virtual string jsonOut() const {
- return "{ \"a\" : null }";
- }
};
class EscapedCharacters : public TestRoundTrip {
diff --git a/src/mongo/scripting/mozjs/valuereader.cpp b/src/mongo/scripting/mozjs/valuereader.cpp
index 292bb32f936..c80efc017da 100644
--- a/src/mongo/scripting/mozjs/valuereader.cpp
+++ b/src/mongo/scripting/mozjs/valuereader.cpp
@@ -103,11 +103,13 @@ void ValueReader::fromBSONElement(const BSONElement& elem, const BSONObj& parent
case mongo::Bool:
_value.setBoolean(elem.Bool());
return;
- case mongo::EOO:
case mongo::jstNULL:
- case mongo::Undefined:
_value.setNull();
return;
+ case mongo::EOO:
+ case mongo::Undefined:
+ _value.setUndefined();
+ return;
case mongo::RegEx: {
// TODO parse into a custom type that can support any patterns and flags SERVER-9803