Skip to content

Commit

Permalink
SERVER-1457 make deep copy of NumberLong properly for group
Browse files Browse the repository at this point in the history
  • Loading branch information
astaple committed Sep 9, 2010
1 parent ad131f8 commit 7c3493d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions jstests/group6.js
Expand Up @@ -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" );
4 changes: 4 additions & 0 deletions shell/mongo_vstudio.cpp
Expand Up @@ -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"
Expand Down
6 changes: 5 additions & 1 deletion shell/utils.js
Expand Up @@ -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;
}
Expand Down

0 comments on commit 7c3493d

Please sign in to comment.