Skip to content
Browse files

SERVER-1457 make deep copy of NumberLong properly for group

  • Loading branch information...
1 parent ad131f8 commit 7c3493d6520b78c2a733555d80bce559a50edd00 @astaple astaple committed
Showing with 10 additions and 1 deletion.
  1. +1 −0 jstests/group6.js
  2. +4 −0 shell/mongo_vstudio.cpp
  3. +5 −1 shell/utils.js
View
1 jstests/group6.js
@@ -29,3 +29,4 @@ for( i = 1; i <= 10; ++i ) {
assert.eq.automsg( "55", "t.group( {key:'y', reduce:function(doc,out){ out.i += doc.i; }, initial:{i:0} } )[ 0 ].i" );
+assert.eq.automsg( "NumberLong(10)", "t.group( {$reduce: function(doc, prev) { prev.count += 1; }, initial: {count: new NumberLong(0) }} )[ 0 ].count" );
View
4 shell/mongo_vstudio.cpp
@@ -216,8 +216,12 @@ const StringData _jscode_raw_utils =
"for ( var k in src ){\n"
"var v = src[k];\n"
"if ( deep && typeof(v) == \"object\" ){\n"
+"if ( \"floatApprox\" in v ) {\n"
+"eval( \"v = \" + tojson( v ) );\n"
+"} else {\n"
"v = Object.extend( typeof ( v.length ) == \"number\" ? [] : {} , v , true );\n"
"}\n"
+"}\n"
"dst[k] = v;\n"
"}\n"
"return dst;\n"
View
6 shell/utils.js
@@ -211,7 +211,11 @@ Object.extend = function( dst , src , deep ){
for ( var k in src ){
var v = src[k];
if ( deep && typeof(v) == "object" ){
- v = Object.extend( typeof ( v.length ) == "number" ? [] : {} , v , true );
+ if ( "floatApprox" in v ) { // convert NumberLong properly
+ eval( "v = " + tojson( v ) );
+ } else {
+ v = Object.extend( typeof ( v.length ) == "number" ? [] : {} , v , true );
+ }
}
dst[k] = v;
}

0 comments on commit 7c3493d

Please sign in to comment.
Something went wrong with that request. Please try again.