Comment on page
Operations
Operation defaults are bypassCreateAcl(false), dryRun(false), grant(null), lean(true), skipAcl(false).
bypassCreateAcl(bool = true)
dryRun(bool = true)
execute()
grant(level)
lean(bool = true)
locale(identifier)
skipAcl(bool = true)
const Items = org.objects.c_items;
const _id = Items.insertOne({c_key: 'unique key'}).execute();
return Items.find({_id: _id}).paths('c_key').next();
Skips createAcl checks.
Arguments
bool
(Boolean)
Returns
this
The operation performs a dry run. Though no documents are inserted, before triggers are called.
Arguments
bool
(Boolean)
Returns
this
Executes the operation.
Returns
ObjectID|Object If the lean option is turned off, the inserted document is returned. When true, only the inserted identifier is returned.
Sets the grant level for the operation.
Arguments
level
(Number)
Returns
this
On by default, turning off this option reads the entire inserted document after execution.
Arguments
bool
(Boolean)
Returns
this
Specifies the locale of the operation for any localized strings.
Arguments
identifier
(String) The locale identifier, which consists of a 2 or 3 letter language tag optionally followed by a region separated by_
. For example,en
,en_US
,en_UK
, etc.
Returns
this
Skips acl checks.
Arguments
bool
(Boolean)
Returns
this
Arguments
operation
{ Object }options
{ Object }operation
{ String } The operation (insertMany, bulk, etc.)object
{ String } New objectname
{ String } Custom name for wrappingas
{ String } Account, safe, principal, acl, or moduleprivileged
{ Boolean } Also pass the user options as privileged optionscursor
{ Object }wrap
{ Boolean }halt
{ Boolean }depth
{ Number }memo
{ Object }
Returns
- { Object } The Operation instance.
Arguments
options
{ Object }onComplete
{ String } Adhoc script that runs when async operation completeslock
{ Object }name
{ String } env unique lock namerestart
{ Boolean } If true, either starts a new op or signal an existing lock of the same name to restart. If false and a lock exists, throws cortex.conflict.lockExistsonSignal
{ String } Adhoc script that runs if the lock is signalled. (restart, cancel, shutdown, error)
Returns
- { Object } The Operation instance.
onComplete receives 3 script arguments
err
{ Object } A fault caught during the bulk operation or null if there was noneoperation
{ Object } the current operation state (same as the return value of the initial next())memo
{ Object } the shared bulk memo object
onSignal receives 1 script argument
signal
{ String } The signal restart, cancel, shutdown, error
const { bulk, Account } = org.objects
return bulk().add(
Account.find(),
{ privileged: true }
)
.async({
onComplete: `
const { err, operation, memo } = script.arguments
console.log({ err, operation, memo })
`,
lock: {
onSignal: `
const { signal } = script.arguments`
}
}).next()
Arguments
options
{ String } Transform scriptscript
{ string | id | export | model } Transform scriptcompiled
{ String } Pre-compiled scriptautoPrefix
{ Boolean }memo
{ Object }required
{ String[] } Pre-existing listlabel
{ String } Transform label. Defaults to 'Transform'
Returns
- { Object } The Operation instance
Operation defaults are dryRun(false), grant(null), lean(true), skipAcl(false).
const Items = org.objects.c_items;
const _id = Items.updateOne({c_key: 'unique key'}, {c_key: 'very unique'})
.skipAcl()
.grant(consts.accessLevels.update)
.execute();
return Items.find({_id: _id}).paths('c_key').next();
The operation performs a dry run. Though no documents are updated, before triggers are called.
Arguments
bool
(Boolean)
Returns
this
Executes the operation.
Returns
ObjectID|Object If the lean option is turned off, the entire updated document is returned. When true, only the identifier is returned.
Sets the grant level for the operation.
Arguments
level
(Number)
Returns
this
True by default, disabling this option reads and returns the entire updated document after execution.
"modified"
may also be used to return an object containing just the modified properties. Otherwise, simply the _id
of the updated document is returned.Arguments
bool
(Boolean)
Returns
this
Specifies the locale of the operation for any localized strings.
Arguments
identifier
(String) The locale identifier, which consists of a 2 or 3 letter language tag optionally followed by a region separated by_
. For example,en
,en_US
,en_UK
, etc.
Returns
this
Enabling this option allows for an update operation on an array to include elements with and without identifiers. Elements with identifiers will update the existing array elements while those without identifiers will be pushed into the array as new elements. If disabled, and the update operation includes a mix of elements with and without identifiers, a
kInvalidArgument
will be returned with the reason "Pushed document has an _id and/or updated document is missing an _id."Arguments
bool
(Boolean)
Returns
this
Deletes a single property or array value using the current cursor options. Passing a path argument overwrites the
pathPrefix()
option. For example, org.objects.c_object.updateOne({_id: _id}).pathDelete("c_docs.5a2c44f836412438e4c372c2.c_array.bar");
removes "bar" from the c_array string array in the c_docs document array.Arguments
path
(String) Optional. OverridespathPrefix()
.
Returns
Object
Sets or removes the operation path prefix. When a prefix is present the operation can target documents in a write-through list or nested document array. For example,
c_parent.updateOne({_id: parentId}, {$push: [{c_name: 'new child'}]}).pathPrefix('c_children').execute()
creates a new c_child instance through the c_parent object's c_children list property.Arguments
path
(String)
Returns
this
Shortcut for updateOne(..., {$push: [body]}).pathPrefix(path).execute()
Arguments
path
(String) Optional. OverridespathPrefix()
.body
(Object) The value(s) to push.
Returns
Object
Shortcut for updateOne(..., {$set: [body]}).pathPrefix(path).execute()
Arguments
path
(String) Optional. OverridespathPrefix()
.body
(Object) The value(s) to update.
Returns
Object
Skips property acl checks.
Arguments
bool
(Boolean)
Returns
this
Operation defaults are dryRun(false), grant(null), skipAcl(false).
const Items = org.objects.c_items;
return Items.deleteOne({c_key: 'unique key'})
.skipAcl()
.grant(consts.accessLevels.delete)
.execute();
The operation performs a dry run. Though no documents are deleted, before triggers are called.
Arguments
bool
(Boolean)
Returns
this
Executes the operation.
Returns
Boolean true if the instance was deleted.
Sets the grant level for the operation.
Arguments
level
(Number)
Returns
this
Skips acl checks.
Arguments
bool
(Boolean)
Returns
this
Last modified 2yr ago