Server-side JavaScript

Loading Data

In this step of the tutorial, we will load some JSON documents using the built-in xdmp.documentInsert() function. declareUpdate() tells the transaction manager that the current statement intends to change the database. Transactions are scoped to the entire statement.

The code below loops through an array an inserts each JavaScript object as a document. We pass four parameters to xdmp.documentInsert(). The first is a URI that uniquely identifies the current document within the MarkLogic database. The second parameter is the data -- the document contents. Third, we pass xdmp.defaultPermissions(). MarkLogic uses a document-level, role-based security model. The xdmp.defaultPermissions() function looks up what permissions the current user grants to new documents; these are passed in to control access to the document being created. The last parameter is an array of collections for the document. Collections are used to group content with the database.

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