# 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**

[AggregationCursor](https://docs.medable.com/reference#aggregationcursor)

### 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**

([DeleteOperation](https://docs.medable.com/reference#deleteoperation))

### find(match)

Returns a cursor based on the passed in `match` filter.

**Arguments**

* `match` (Object) Match filter document.

**Returns**

[QueryCursor](https://docs.medable.com/reference#querycursor)

### insertOne(doc)

Returns an insert operation.

**Arguments**

* `doc` (Object) The document to insert.

**Returns**

[InsertOperation](https://docs.medable.com/reference#insertoperation)

### 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`.

{% hint style="warning" %}
setOwner is a low-level operation and does not implement any access controls, though an Audit log record is produced.
{% endhint %}

### 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**

[UpdateOperation](https://docs.medable.com/reference#updateoperation)\
const Nums = CortexObject.as('c\_nums');

```

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.medable.com/cortex-api/scripting/static-methods.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
