0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

Shard key in upsert query must be exact match SERVER-1689

This commit is contained in:
Mathias Stearn 2010-09-02 21:11:53 -04:00
parent 2543ea4f76
commit 6cc10ef09e

View File

@ -185,10 +185,17 @@ namespace mongo {
uassert( 10202 , "can't mix multi and upsert and sharding" , ! ( upsert && multi ) );
if ( upsert && !(manager->hasShardKey(toupdate) ||
(toupdate.firstElement().fieldName()[0] == '$' && manager->hasShardKey(query))))
{
throw UserException( 8012 , "can't upsert something without shard key" );
if (upsert){
uassert(8012, "can't upsert something without shard key",
(manager->hasShardKey(toupdate) ||
(toupdate.firstElement().fieldName()[0] == '$' && manager->hasShardKey(query))));
BSONObj key = manager->getShardKey().extractKey(query);
BSONForEach(e, key){
PRINT(e);
PRINT(getGtLtOp(e));
uassert(13465, "shard key in upsert query must be an exact match", getGtLtOp(e) == BSONObj::Equality);
}
}
bool save = false;