mirror of
https://github.com/mongodb/mongo.git
synced 2024-11-30 17:10:48 +01:00
Sharding: save() support SHARDING-17
This commit is contained in:
parent
7d9befe0e0
commit
d7889fb311
@ -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();
|
||||
|
@ -126,11 +126,16 @@ namespace mongo {
|
||||
if ( upsert && ! manager->hasShardKey( toupdate ) )
|
||||
throw UserException( "can't upsert something without shard key" );
|
||||
|
||||
if ( ! manager->hasShardKey( query ) )
|
||||
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() );
|
||||
|
Loading…
Reference in New Issue
Block a user