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
  • Static Methods
  • as(objectName)
  • from(context)
  • aggregate(pipeline=[])
  • count(match)
  • deleteOne(match)
  • find(match)
  • insertOne(doc)
  • setOwner(id, to)
  • updateOne(match, doc)

Was this helpful?

  1. Cortex API
  2. Scripting

Static Methods

Static Methods

as(objectName)

Extends CortexObject and returns a class with a constructor name matching objectName.

Arguments

  • objectName (String)

Returns

ClassJavaScript

const Nums = CortexObject.as('c_num');
const _id = Nums.insertOne({c_val: [1, 2, 3]}).execute();

from(context)

Returns an instance of a CortexObject based on the passed in context argument, which should have at least _id and object properties.

Arguments

  • context (Object)

Returns

CortexObject instance

aggregate(pipeline=[])

Returns an aggregation cursor based on the optional passed in pipeline argument. The pipeline must be in the form of an array and named aggregation steps ([{$match: {...}}, {$project: {...}}, ...]). A pipeline can also be built later using aggregation cursor chaining.

Arguments

  • pipeline (Object[])

Returns

count(match)

Returns a count of matching documents of the current CortexObject.

Arguments

  • match (Object) Optional match filter document.

Returns

Number

deleteOne(match)

Returns a delete operation based on the passed in match filter.

Arguments

  • match (Object) Optional match filter document.

Returns

find(match)

Returns a cursor based on the passed in match filter.

Arguments

  • match (Object) Match filter document.

Returns

insertOne(doc)

Returns an insert operation.

Arguments

  • doc (Object) The document to insert.

Returns

setOwner(id, to)

Transfers ownership of a context object to another account.

Arguments

  • id (ObjectID) The identifier of the instance to update.

  • to (ObjectID|String) The identifier or email of the new owner account.

Returns

Boolean true is modified or false if already owned by to.

setOwner is a low-level operation and does not implement any access controls, though an Audit log record is produced.

updateOne(match, doc)

Returns an update operation based on the passed in match filter.

$set and $push operations support updating existing document array elements by including their identifiers (e.g. push 2 items into c_arr of a specific document in the c_docs document array: { $push: {c_docs: {_id: '599284e01c9e955ff7526793', c_arr: [1, 2] }}}).

$unset operations can remove properties buried in specific documents

Arguments

  • match (Object) Optional match filter document.

  • doc (Object) An object containing the changes to effect. Update supports $set, $push, $unset and $remove.

    • $set Contains properties to update. (e.g. {$set: {name: {first: 'Auric', last: 'Goldfinger'}}})

    • $push Contains items to push into arrays and document arrays (e.g. {$push: {c_names: ['Jill Masterson']}})

    • $unset Unset one or more deletable properties (e.g. {$unset: {'c_doc.59928b74341a65ef3f03842b.c_deletable': 1, c_remove_me: 1}}).

    • $remove Removes elements from arrays, by full path (e.g. remove 2 documents from c_doc_array by identifier and all 1 and 2 values from c_num_arr in the c_doc_array document with an identifier of 59928b74341a65ef3f03842b: $remove: {'c_doc_array': ['59928aed341a65ef3f03836a', '59928af9341a65ef3f038380'], 'c_doc_array.59928b74341a65ef3f03842b.c_num_arr': [1,2] })

Returns


Nums.updateOne({_id: '5992879ef4e03e6c3f682c5e'}, {
  $push: {    
    c_doc: {
      c_arr: [1, 2, 3]
    }
  },
  $set: {
    c_doc: [{
      _id: '59928b74341a65ef3f03842b',
      c_del: 420,
      c_arr: [1, 2, 3, 4]
    }]
  },
  $unset: {
    'c_doc.59928b74341a65ef3f03842b.c_del': 1
  },
  $remove: {
    c_doc: ['59928aed341a65ef3f03836a', '59928af9341a65ef3f038380']
    'c_doc.59928b74341a65ef3f03842b.c_arr': [1,2]
  }
}).execute();

Last updated 3 years ago

Was this helpful?

()

const Nums = CortexObject.as('c_nums');

AggregationCursor
DeleteOperation
QueryCursor
InsertOperation
UpdateOperation