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

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)

find(match)

Returns a cursor based on the passed in match filter.

Arguments

  • match (Object) Match filter document.

Returns

QueryCursor

insertOne(doc)

Returns an insert operation.

Arguments

  • doc (Object) The document to insert.

Returns

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.

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

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

Last updated