Loading TOC...


   schema-name as String,
   name as String,
   scope as element(*,view.viewScope),
   columns as element(view.column)[],
   fields as element(view.field)[],
   permissions as Sequence
) as (Number|String)


This function creates a new view in the specified schema specification. The id of the view is returned. The view is checked for validity.

Prior to executing this function, you must create a range index for each column in your view. For details on element range indexes, see Range Indexes and Lexicons in the Administrator's Guide.

schema-name The name of the schema specification in which the view is created.
name The name of the view. The view name must be unique in the context of the schema in which it is created. A valid view name is a single word that starts with an alpha character. The view name may contain numeric characters, but cannot contain punctuation or special characters.
scope The scope of the view used to constrain the subset of the database to which the view applies. The scope can either limit rows in the view to documents with a specific element (localname + namespace) or to documents in a particular collection. Use the view:element-view-scope function to set the scope to an element or the view:collection-view-scope function to set the scope to a collection.

For details on view scoping, see Defining View Scope in the SQL Data Modeling Guide.

columns A sequence of view columns. Each column has a name and a range index reference.
fields A sequence of view fields. Each field has a name and a field reference.
permissions The permissions required to access this view. When run in an XQuery context, the permissions are a sequence of XML elements (sec:permission). When importing this module into a Server-Side JavaScript context, the permissions are an array of Objects.


const view = require('/MarkLogic/views');

      ( view.column('uri', cts.uriReference()), 
        view.column('title', cts.elementReference(xs.QName('TITLE'))),
        view.column('album', cts.elementReference(xs.QName('ALBUM'), ('nullable'))),
        view.column('year', cts.elementReference(xs.QName('YEAR'))))

  // Creates a view, named 'songs', of the 'main' schema that contains four columns, 
  // with a scope on the element, 'SONG'.

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.