From 278f1b43f51a62989ac91741b20fbf3adb6733b2 Mon Sep 17 00:00:00 2001 From: Scott Hernandez Date: Mon, 30 Sep 2013 17:28:14 -0400 Subject: [PATCH] SERVER-1534 SERVER-10911: enable curentDate/min/max mods --- jstests/verify_update_mods.js | 73 +++++++++++++++++++++++++++++ src/mongo/db/ops/modifier_table.cpp | 17 +++++++ src/mongo/db/ops/modifier_table.h | 4 ++ 3 files changed, 94 insertions(+) create mode 100644 jstests/verify_update_mods.js diff --git a/jstests/verify_update_mods.js b/jstests/verify_update_mods.js new file mode 100644 index 0000000000000..65f1f826bf5fc --- /dev/null +++ b/jstests/verify_update_mods.js @@ -0,0 +1,73 @@ +// Verify update mods exist +t = db.update_mods; +t.drop(); + +t.save({_id:1}); +t.update({}, {$set:{a:1}}) +assert.automsg( "!db.getLastError()" ); +t.remove() + +t.save({_id:1}); +t.update({}, {$unset:{a:1}}) +assert.automsg( "!db.getLastError()" ); +t.remove() + +t.save({_id:1}); +t.update({}, {$inc:{a:1}}) +assert.automsg( "!db.getLastError()" ); +t.remove() + +t.save({_id:1}); +t.update({}, {$mul:{a:1}}) +assert.automsg( "!db.getLastError()" ); +t.remove() + +t.save({_id:1}); +t.update({}, {$push:{a:1}}) +assert.automsg( "!db.getLastError()" ); +t.remove() + +t.save({_id:1}); +t.update({}, {$pushAll:{a:[1]}}) +assert.automsg( "!db.getLastError()" ); +t.remove() + +t.save({_id:1}); +t.update({}, {$addToSet:{a:1}}) +assert.automsg( "!db.getLastError()" ); +t.remove() + +t.save({_id:1}); +t.update({}, {$pull:{a:1}}) +assert.automsg( "!db.getLastError()" ); +t.remove() + +t.save({_id:1}); +t.update({}, {$pop:{a:true}}) +assert.automsg( "!db.getLastError()" ); +t.remove() + +t.save({_id:1}); +t.update({}, {$rename:{a:"b"}}) +assert.automsg( "!db.getLastError()" ); +t.remove() + +t.save({_id:1}); +t.update({}, {$bit:{a:{and:NumberLong(1)}}}) +assert.automsg( "!db.getLastError()" ); +t.remove() + +t.save({_id:1}); +t.update({}, {$currentDate:{a:true}}) +assert.automsg( "!db.getLastError()" ); +t.remove() + +t.save({_id:1}); +t.update({}, {$max:{a:1}}) +assert.automsg( "!db.getLastError()" ); +t.remove() + +t.save({_id:1}); +t.update({}, {$min:{a:1}}) +assert.automsg( "!db.getLastError()" ); +t.remove() diff --git a/src/mongo/db/ops/modifier_table.cpp b/src/mongo/db/ops/modifier_table.cpp index 00713ef0efc8a..31d4095160a03 100644 --- a/src/mongo/db/ops/modifier_table.cpp +++ b/src/mongo/db/ops/modifier_table.cpp @@ -35,6 +35,8 @@ #include "mongo/base/status.h" #include "mongo/db/ops/modifier_add_to_set.h" #include "mongo/db/ops/modifier_bit.h" +#include "mongo/db/ops/modifier_compare.h" +#include "mongo/db/ops/modifier_current_date.h" #include "mongo/db/ops/modifier_inc.h" #include "mongo/db/ops/modifier_pop.h" #include "mongo/db/ops/modifier_pull.h" @@ -71,9 +73,18 @@ namespace modifiertable { ModifierEntry* entryBit = new ModifierEntry("$bit", MOD_BIT); nameMap->insert(make_pair(StringData(entryBit->name), entryBit)); + ModifierEntry* entryCurrentDate = new ModifierEntry("$currentDate", MOD_CURRENTDATE); + nameMap->insert(make_pair(StringData(entryCurrentDate->name), entryCurrentDate)); + ModifierEntry* entryInc = new ModifierEntry("$inc", MOD_INC); nameMap->insert(make_pair(StringData(entryInc->name), entryInc)); + ModifierEntry* entryMax = new ModifierEntry("$max", MOD_MAX); + nameMap->insert(make_pair(StringData(entryMax->name), entryMax)); + + ModifierEntry* entryMin = new ModifierEntry("$min", MOD_MIN); + nameMap->insert(make_pair(StringData(entryMin->name), entryMin)); + ModifierEntry* entryMul = new ModifierEntry("$mul", MOD_MUL); nameMap->insert(make_pair(StringData(entryMul->name), entryMul)); @@ -128,8 +139,14 @@ namespace modifiertable { return new ModifierAddToSet; case MOD_BIT: return new ModifierBit; + case MOD_CURRENTDATE: + return new ModifierCurrentDate; case MOD_INC: return new ModifierInc(ModifierInc::MODE_INC); + case MOD_MAX: + return new ModifierCompare(ModifierCompare::MAX); + case MOD_MIN: + return new ModifierCompare(ModifierCompare::MIN); case MOD_MUL: return new ModifierInc(ModifierInc::MODE_MUL); case MOD_POP: diff --git a/src/mongo/db/ops/modifier_table.h b/src/mongo/db/ops/modifier_table.h index a19a57d769f06..69aadab0839d4 100644 --- a/src/mongo/db/ops/modifier_table.h +++ b/src/mongo/db/ops/modifier_table.h @@ -33,10 +33,14 @@ namespace mongo { namespace modifiertable { + // NOTE: Please update jstests/verify_update_mods.js or include a jstest for any new mods enum ModifierType { MOD_ADD_TO_SET, MOD_BIT, + MOD_CURRENTDATE, MOD_INC, + MOD_MAX, + MOD_MIN, MOD_MUL, MOD_POP, MOD_PULL,