LogoLogo
  • Introduction
  • Features
  • Getting Started
    • Cortex User Guide
      • Organizations
      • Log in
      • Generate an API key
      • Make your first API request
      • Configure the org settings
      • Set up a data model
        • Create custom objects
        • Add custom properties
      • One-to-many relationships
      • Read and write data
      • Making a Request
      • Handling responses
      • Authentication
      • Two-factor authentication
      • Set third-party cookies
      • Connections
      • Upload files
      • Cortex iOS
      • Get started with Swift
      • Cortex service accounts
      • Cortex developer tools
      • Automated Account Notifications
  • Cortex API
    • Overview
    • Objects
      • Objects Overview
      • Organization
      • Account
      • Connections
      • Notifications
      • Stats
      • Logs
      • Export
      • Events
      • Room
    • Object Definition
      • Object Properties
        • Any
        • Binary
        • Boolean
        • Date
        • Document
        • File
        • Geometry
        • List
        • Number
        • ObjectId
        • Reference
        • String
    • Object Types
    • Access Control
    • Querying
      • Query Operators
      • Property Selection
      • Property Access
    • Aggregating
      • Aggregation Operators
    • Scripting
      • Script Types
      • Script Limits
      • ObjectId
      • CortexObject
        • Accounts
        • Views
      • Cursors
      • Operations
      • Script Modules
        • API Module
        • Base64 Module
        • Cache Module
        • Connections Module
        • Console Module
        • Consts Module
        • Counters Module
        • Crypto Module
        • HTTP Module
        • Logger Module
        • Notifications Module
        • Request Module
        • Response Module
        • SAML Module
        • Schemas Modules
        • Script Module
        • Session Module
        • Util.id Module
        • Util.ip Module
        • Util.paths Module
        • XML Module
        • Developer
        • Config
        • Renderer
        • SFTP
        • FTP
        • DB
          • Cursors
          • Driver
      • Static Methods
        • Accounts
        • Views
        • Cursors
      • Audit
      • Environments
      • HTTP Driver
      • Notifications
        • Firebase Cloud Messaging (FCM)
        • Tencent Push Notification Service Configuration
      • Televisit
      • Transforms
      • Localization
      • Available Javascript Libraries
    • Decorators
      • Runtime
        • Acl
        • As
        • Log
        • Profile
      • Static
        • Env
        • Job
        • Object
        • On
        • Policy
        • Route
        • Transform
        • Trigger
    • Expressions
      • Primer
      • Pipelines
      • Operators
      • Accumulators
      • Variables
      • Conditionals
      • Transforms
      • Triggers
      • On
      • Events
    • Faults
      • Fault Reference
  • Releases
    • Cortex Release Notes
      • Cortex API 2.28.3 (R3.4.6)
      • Cortex API 2.28.1 (R3.4.3)
      • Cortex API 2.27.2 (R3.4.1)
      • Cortex API 2.27.1 (R3.3.5)
      • SQL DB Connector 1.3.4 (R3.3.3)
      • Cortex API 2.26.2 (R3.3.1)
      • Cortex API 2.26.1 (R3.2.2)
      • Cortex API 2.26.0 (R3.2.1)
      • SQL DB Connector 1.3.3
      • Cortex API 2.25.0 (R3.1.1)
      • SQL DB Connector 1.3.2 (R3.1.0)
      • Cortex API 2.24.2 (R3.0.2)
      • SQL DB Connector 1.3.1 (R3.0.0)
      • Cortex API 2.24.1 (R2.3.3)
      • Cortex API 2.24.0 (R2.3.2)
      • SQL DB Connector 1.3.0 (R2.3.0)
      • Cortex API 2.23.0 (R2.2.4)
      • SQL DB Connector 1.2.0 (R2.2.0)
      • Cortex API 2.22.2 (R2.1.2)
      • Cortex API 2.22.1 and SQL DB Connector 1.1.1 (R2.0.1)
      • Cortex API 2.22.0
      • Cortex API 2.21.3
      • Cortex API 2.21.2
      • Cortex Web 4.16.0
      • Cortex Web 4.15.1
      • Cortex API 2.20.1
      • Cortex Web 4.14.0
      • Cortex Renderer 1.3.3
      • Cortex API 2.19.4
      • Cortex API 2.19.3 and Cortex Web 4.13.1
      • Cortex Renderer 1.3.2
      • Cortex API 2.19.1
      • Cortex API 2.18.0
      • Cortex API 2.17.6
      • Cortex API 2.17.5
      • Cortex API 2.17.4
      • Cortex API 2.17.3
      • Cortex API 2.17.2
      • Cortex API 2.17.1
      • Cortex API 2.16.0
      • Cortex API 2.15.9
      • Cortex API 2.15.8-1
      • Cortex 2.15.8
      • Cortex API 2.18.1
      • Cortex API 2.16.1
      • Cortex Renderer 1.3.1
      • Cortex Renderer 1.3.0
      • Cortex Renderer 1.2.2
      • Cortex Renderer 1.2.1
      • Cortex Renderer 1.2.0
    • Third-Party License Attribution

© 2025 Medable, Inc. All rights reserved.

On this page
  • InsertOperation
  • InsertOperation.bypassCreateAcl(bool = true)
  • InsertOperation.dryRun(bool = true)
  • InsertOperation.execute()
  • InsertOperation.grant(level)
  • InsertOperation.lean(bool = true)
  • InsertOperation.locale(identifier)
  • InsertOperation.skipAcl(bool = true)
  • class BulkOperation
  • add(operation, options)
  • async(options)
  • transform(options)
  • UpdateOperation
  • UpdateOperation.dryRun(bool = true)
  • UpdateOperation.execute()
  • UpdateOperation.grant(level)
  • UpdateOperation.lean(bool = true)
  • UpdateOperation.locale(identifier)
  • UpdateOperation.merge(bool)
  • UpdateOperation.pathDelete(path = null)
  • UpdateOperation.pathPrefix(path = null)
  • UpdateOperation.pathPush(path = null, body)
  • UpdateOperation.pathUpdate(path = null, body)
  • UpdateOperation.skipAcl(bool = true)
  • DeleteOperation
  • DeleteOperation.dryRun(bool = true)
  • DeleteOperation.execute()
  • DeleteOperation.grant(level)
  • DeleteOperation.skipAcl(bool = true)

Was this helpful?

  1. Cortex API
  2. Scripting

Operations

InsertOperation

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();

InsertOperation.bypassCreateAcl(bool = true)

Skips createAcl checks.

Arguments

  • bool (Boolean)

Returns

this

InsertOperation.dryRun(bool = true)

The operation performs a dry run. Though no documents are inserted, before triggers are called.

Arguments

  • bool (Boolean)

Returns

this

InsertOperation.execute()

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.

InsertOperation.grant(level)

Sets the grant level for the operation.

Arguments

  • level (Number)

Returns

this

InsertOperation.lean(bool = true)

On by default, turning off this option reads the entire inserted document after execution.

Arguments

  • bool (Boolean)

Returns

this

InsertOperation.locale(identifier)

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

InsertOperation.skipAcl(bool = true)

Skips acl checks.

Arguments

  • bool (Boolean)

Returns

this

class BulkOperation

add(operation, options)

Arguments

  • operation { Object }

  • options { Object }

    • operation { String } The operation (insertMany, bulk, etc.)

    • object { String } New object

    • name { String } Custom name for wrapping

    • as { String } Account, safe, principal, acl, or module

    • privileged { Boolean } Also pass the user options as privileged options

    • cursor { Object }

    • wrap { Boolean }

    • halt { Boolean }

    • depth { Number }

    • memo { Object }

Returns

  • { Object } The Operation instance.

async(options)

Arguments

  • options { Object }

    • onComplete { String } Adhoc script that runs when async operation completes

    • lock { Object }

      • name { String } env unique lock name

      • restart { 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.lockExists

      • onSignal { 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 none

  • operation { 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()

transform(options)

Arguments

  • options { String } Transform script

    • script { string | id | export | model } Transform script

    • compiled { String } Pre-compiled script

    • autoPrefix { Boolean }

    • memo { Object }

    • required { String[] } Pre-existing list

    • label { String } Transform label. Defaults to 'Transform'

Returns

  • { Object } The Operation instance

UpdateOperation

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();

UpdateOperation.dryRun(bool = true)

The operation performs a dry run. Though no documents are updated, before triggers are called.

Arguments

  • bool (Boolean)

Returns

this

UpdateOperation.execute()

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.

UpdateOperation.grant(level)

Sets the grant level for the operation.

Arguments

  • level (Number)

Returns

this

UpdateOperation.lean(bool = true)

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

UpdateOperation.locale(identifier)

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

UpdateOperation.merge(bool)

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

UpdateOperation.pathDelete(path = null)

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. Overrides pathPrefix().

Returns

Object

UpdateOperation.pathPrefix(path = null)

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

UpdateOperation.pathPush(path = null, body)

Shortcut for updateOne(..., {$push: [body]}).pathPrefix(path).execute()

Arguments

  • path (String) Optional. Overrides pathPrefix().

  • body (Object) The value(s) to push.

Returns

Object

UpdateOperation.pathUpdate(path = null, body)

Shortcut for updateOne(..., {$set: [body]}).pathPrefix(path).execute()

Arguments

  • path (String) Optional. Overrides pathPrefix().

  • body (Object) The value(s) to update.

Returns

Object

UpdateOperation.skipAcl(bool = true)

Skips property acl checks.

Arguments

  • bool (Boolean)

Returns

this

DeleteOperation

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();

DeleteOperation.dryRun(bool = true)

The operation performs a dry run. Though no documents are deleted, before triggers are called.

Arguments

  • bool (Boolean)

Returns

this

DeleteOperation.execute()

Executes the operation.

Returns

Boolean true if the instance was deleted.

DeleteOperation.grant(level)

Sets the grant level for the operation.

Arguments

  • level (Number)

Returns

this

DeleteOperation.skipAcl(bool = true)

Skips acl checks.

Arguments

  • bool (Boolean)

Returns

this

Last updated 3 years ago

Was this helpful?

JavaScript

dryRun(bool = true)
execute()
grant(level)
skipAcl(bool = true)