Collections

This controller expose operation to manipulate Collections

collections.delete(schema: string, documentId: string)

Deletes a given element from a collection.

Arguments:
  • schema – Item ID of the schema.collections.

  • documentId – Id Mongo of the document to delete

collections.get(schema: string, documentId: string)

Search for the first element from one collection and filter by document id

Arguments:
  • schema – Item ID of the schema.collections.

  • documentId – Id Mongo of the document to get.

Returns:

An object with attribute :

  • success (boolean) Indicates whether the operation was successful.

  • message (string) Contains additional information about the operation’s success or failure.

  • content (object) Data returned from a successful request.

Type of the data is different for each request type. Each operation presented below explain what you should expect from the content of the request

content hold the result of the query:

  • content.document contains the element found

collections.getHistory(schema: string, documentId: string)

Get history of all revisions of a document

Arguments:
  • schema

  • documentId

Returns:

Object with preperties collections, that content a list of all versions record of the document linked with documentId

collections.getUserAttributeFromPreferences(attribute: string, defaultValue?: object)

Get the value associated with attribute from the currently authenticated user preferences.

Arguments:
  • attribute

  • defaultValue

Returns:

Return the attribute linked to user that initiate an action that imply the script execution (like pressing a button). If no value is found, defaultValue is returned instead. If not specified, null is returned instead.

collections.getUsername()

This method allow to get username of user that is authenticated and did an action that run the script. This information is accessible only if the script is trigger by a front-end action, like a menu for example. Otherwise, this will return an empty string.

Returns:

Return a string that represent username that triggered the script.

collections.getWithCustomFilter(schema: string, filter: string)

Same as get() using a custom string filter

Arguments:
  • schema

  • filter

Returns:

Same get().

collections.getWithFilterId(schema: string, filter: string)

Same as get() using filter from the configuration

Arguments:
  • schema – Item ID of the schema.collections.

  • filter – Id of the filter defined in the configuration in schema.collections or in schema.ospp.

Returns:

Same get().

collections.insert(schema: string, data: object)

Insert a new element into a collection

Arguments:
  • schema

  • data

Returns:

An object with attribute :

  • success (boolean) Indicates whether the operation was successful.

  • message (string) Contains additional information about the operation’s success or failure.

  • content (object) Data returned from a successful request.

Type of the data is different for each request type. Each operation presented below explain what you should expect from the content of the request

content hold the result of the query:

  • content.documentId id of the document that has been update.

  • content.operation the operation that has been executed (insert or update).

collections.list(schema: string, pageSize: number, pageNumber: number, filterId?: string)

List elements from one collection that match the given filter id from the schema configuration. Specifies the number of elements (pageSize) and the offset (pageNumber, starts at 0).

Arguments:
  • schema

  • pageSize

  • pageNumber

  • filterId

Returns:

An object with attribute :

  • success (boolean) Indicates whether the operation was successful.

  • message (string) Contains additional information about the operation’s success or failure.

  • content (object) Data returned from a successful request.

Type of the data is different for each request type. Each operation presented below explain what you should expect from the content of the request

content hold the result of the query:

  • content.totalCount contains number of elements found (unbound by the pageSize).

  • content.collections property as an array of documents.

collections.listCustomFilter(schema: string, pageSize: number, pageNumber: number, filter: string)

Same as list() but using custom query string.

Arguments:
  • schema

  • pageSize

  • pageNumber

  • filter – A MongoDB filter.

Returns:

Same as list().

collections.update(schema: string, document: object)

Updates by giving the complete updated object

Arguments:
  • schema

  • document

Returns:

Same as update().

collections.update(schema: string, documentId: string, data: object[])

Update an element from a collection

Arguments:
  • schema

  • documentId

  • data – Updates by giving a list of updates to apply on the element. You can look at the collection documentation to see how to define an update object. If data is an object, update complete collection object.

Returns:

Same insert().