diff --git a/jstests/sharding/shard6.js b/jstests/sharding/shard6.js index 88c809955b7..fab251bc2cf 100644 --- a/jstests/sharding/shard6.js +++ b/jstests/sharding/shard6.js @@ -20,4 +20,20 @@ for ( ; num<100; num++ ){ assert.eq( 100 , db.data.find().toArray().length ); +// limit + +assert.eq( 77 , db.data.find().limit(77).itcount() , "limit test 1" ); +assert.eq( 1 , db.data.find().limit(1).itcount() , "limit test 2" ); +for ( var i=1; i<10; i++ ){ + assert.eq( i , db.data.find().limit(i).itcount() , "limit test 3 : " + i ); +} + + +// --- test save support --- + +o = db.data.findOne(); +o.x = 16; +db.data.save( o ); +assert.eq( 16 , db.data.findOne( { _id : o._id } ).x , "x1 - did save fail?" ); + s.stop(); diff --git a/s/strategy_shard.cpp b/s/strategy_shard.cpp index 761245cc50a..ad6ef99aafe 100644 --- a/s/strategy_shard.cpp +++ b/s/strategy_shard.cpp @@ -126,11 +126,16 @@ namespace mongo { if ( upsert && ! manager->hasShardKey( toupdate ) ) throw UserException( "can't upsert something without shard key" ); - if ( ! manager->hasShardKey( query ) ) - throw UserException( "can't do update with query that doesn't have the shard key" ); + bool save = false; + if ( ! manager->hasShardKey( query ) ){ + if ( query.nFields() != 1 || strcmp( query.firstElement().fieldName() , "_id" ) ) + throw UserException( "can't do update with query that doesn't have the shard key" ); + save = true; + } - if ( manager->hasShardKey( toupdate ) && manager->getShardKey().compare( query , toupdate ) ) + if ( ! save && manager->hasShardKey( toupdate ) && manager->getShardKey().compare( query , toupdate ) ){ throw UserException( "change would move shards!" ); + } Shard& s = manager->findShard( toupdate ); doWrite( dbUpdate , r , s.getServer() );