- Reference >
- Database Commands >
- Replication Commands >
- applyOps
applyOps¶
Definition¶
- applyOps¶
Applies specified oplog entries to a mongod instance. The applyOps command is primarily an internal command.
If authorization is enabled, you must have access to all actions on all resources in order to run applyOps. Providing such access is not recommended, but if your organization requires a user to run applyOps, create a role that grants anyAction on anyResource. Do not assign this role to any other user.
The applyOps command has the following prototype form:
db.runCommand( { applyOps: [ <operations> ], preCondition: [ { ns: <namespace>, q: <query>, res: <result> } ] } )
The applyOps command takes a document with the following fields:
Field Description applyOps The oplog entries to apply. preCondition Optional. An array of documents that contain the conditions that must be true in order to apply the oplog entry. Each document contains a set of conditions, as described in the next table. alwaysUpsert Optional. A flag that indicates whether to apply update operations in the oplog as ref:upserts <write-operations-upsert-behavior>. When true, all updates become upserts to prevent failures as a results of sequences of updates followed by deletes: this is the same mode of operation as normal replication in secondaries. When false, updates are applied unmodified: this is the same mode of operation used during initial sync operations. true by default. The preCondition array takes one or more documents with the following fields:
Field Description ns A namespace. If you use this field, applyOps applies oplog entries only for the collection described by this namespace. q Specifies the query that produces the results specified in the res field. res The results of the query in the q field that must match to apply the oplog entry.
Behavior¶
Warning
This command obtains a global write lock and will block other operations until it has completed.