diff options
Diffstat (limited to 'src/mongo/db/ops/update.h')
-rw-r--r-- | src/mongo/db/ops/update.h | 104 |
1 files changed, 7 insertions, 97 deletions
diff --git a/src/mongo/db/ops/update.h b/src/mongo/db/ops/update.h index f4088c90bc4..8f42e30ac16 100644 --- a/src/mongo/db/ops/update.h +++ b/src/mongo/db/ops/update.h @@ -16,118 +16,28 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "mongo/pch.h" +#pragma once #include "mongo/db/jsobj.h" #include "mongo/db/curop.h" +#include "mongo/db/ops/update_request.h" +#include "mongo/db/ops/update_result.h" #include "mongo/db/query_plan_selection_policy.h" namespace mongo { class UpdateDriver; - // ---------- public ------------- - - struct UpdateResult { - const bool existing; // if existing objects were modified - const bool mod; // was this a $ mod - const long long num; // how many objects touched - OID upserted; // if something was upserted, the new _id of the object - - UpdateResult( bool e, bool m, unsigned long long n , const BSONObj& upsertedObject ) - : existing(e) , mod(m), num(n) { - upserted.clear(); - BSONElement id = upsertedObject["_id"]; - if ( ! e && n == 1 && id.type() == jstOID ) { - upserted = id.OID(); - } - } - }; - - class RemoveSaver; - - /* returns true if an existing object was updated, false if no existing object was found. - multi - update multiple objects - mostly useful with things like $set - su - allow access to system namespaces (super user) - */ - UpdateResult updateObjects(const char* ns, - const BSONObj& updateobj, - const BSONObj& pattern, - bool upsert, - bool multi, - bool logop, - OpDebug& debug, - bool fromMigrate = false, - const QueryPlanSelectionPolicy& planPolicy = QueryPlanSelectionPolicy::any()); - - /** A variant of updateObjects that is only useable if the new update framework is enabled. - * It assumes that the UpdateDriver has already been initialized outside the lock. - */ - UpdateResult updateObjects(UpdateDriver* driver, - const char* ns, - const BSONObj& updateobj, - const BSONObj& pattern, - bool upsert, - bool multi, - bool logop, - OpDebug& debug, - bool fromMigrate = false, - const QueryPlanSelectionPolicy& planPolicy = QueryPlanSelectionPolicy::any()); - - /* - * Similar to updateObjects but not strict about applying mods that can fail during initial - * replication. - * - * Reference ticket: SERVER-4781 - */ - UpdateResult updateObjectsForReplication(const char* ns, - const BSONObj& updateobj, - const BSONObj& pattern, - bool upsert, - bool multi, - bool logop, - OpDebug& debug, - bool fromMigrate = false, - const QueryPlanSelectionPolicy& planPolicy = - QueryPlanSelectionPolicy::any()); - - UpdateResult _updateObjects(bool su, - const char* ns, - const BSONObj& updateobj, - const BSONObj& pattern, - bool upsert, - bool multi, - bool logop, - OpDebug& debug, - RemoveSaver* rs = 0, - bool fromMigrate = false, - const QueryPlanSelectionPolicy& planPolicy - = QueryPlanSelectionPolicy::any(), - bool forReplication = false); - - UpdateResult _updateObjects(UpdateDriver* driver, - bool su, - const char* ns, - const BSONObj& updateobj, - const BSONObj& pattern, - bool upsert, - bool multi, - bool logop, - OpDebug& debug, - RemoveSaver* rs = 0, - bool fromMigrate = false, - const QueryPlanSelectionPolicy& planPolicy - = QueryPlanSelectionPolicy::any(), - bool forReplication = false); + UpdateResult update(UpdateRequest& request); + UpdateResult update(UpdateRequest& request, UpdateDriver* driver); /** * takes the from document and returns a new document - * after apply all the operators - * e.g. + * after apply all the operators + * e.g. * applyUpdateOperators( BSON( "x" << 1 ) , BSON( "$inc" << BSON( "x" << 1 ) ) ); * returns: { x : 2 } */ BSONObj applyUpdateOperators( const BSONObj& from, const BSONObj& operators ); - } // namespace mongo |