Document API

Contents

Usage

In your controller, add a require statement:

import {create, update} from '/lib/explorer/document';

Functions

create

Parameters

Two objects with the following keys and their values:

Data Object
Name Type Attributes Default Details

_name

String

<optional>

If not provided the name will become the same as _id

…​

<optional>

More properties you want to persist

Options Object
Name Type Attributes Default Details

boolRequireValid

boolean

<optional>

true

The data must be valid for the document to be created

connection

<required>

A collection repo connection with write permissions

Returns

If successful the created node.

Example

Executing create in some controller
import {create} from '/lib/explorer/document';
import {
  COLLECTION_REPO_PREFIX,
  PRINCIPAL_EXPLORER_WRITE
} from '/lib/explorer/model/2/constants';

export function post({
  body,
  params: {
    collection
  }
}) {
  create(
    JSON.parse(body), // Data Object
    { // Options Object
      boolRequireValid: true,
      connection: connect({
        branch: 'master',
        principals: [PRINCIPAL_EXPLORER_WRITE],
        repoId: `${COLLECTION_REPO_PREFIX}${collection}`
      })
    }
  );
}

Sample response

{
  _id: '7d28b333-3274-4f26-a2bc-36682602e493',
  _name: 'whatever'
}

update

Parameters

Two objects with the following keys and their values:

Data Object
Name Type Attributes Default Details

_id

<required>

The id of the document you want to update

…​

<optional>

More properties you want to persist

Options Object
Name Type Attributes Default Details

boolPartial

boolean

<optional>

false

When true, values are only added or updated. Unprovided values are not removed.

boolRequireValid

boolean

<optional>

true

The data must be valid for the document to be updated

connection

<required>

A collection repo connection with write permissions

Returns

If successful the updated node.

Example

Executing create in some controller
import {update} from '/lib/explorer/document';
import {
  COLLECTION_REPO_PREFIX,
  PRINCIPAL_EXPLORER_WRITE
} from '/lib/explorer/model/2/constants';

export function post({
  body,
  params: {
    collection
  }
}) {
  update(
    JSON.parse(body), // Data Object
    { // Options Object
      boolPartial: false,
      boolRequireValid: true,
      connection: connect({
        branch: 'master',
        principals: [PRINCIPAL_EXPLORER_WRITE],
        repoId: `${COLLECTION_REPO_PREFIX}${collection}`
      })
    }
  );
}

Sample response

{
  _id: '7d28b333-3274-4f26-a2bc-36682602e493',
  _name: 'changed'
}

Contents

Contents