Loading TOC...

MarkLogic 12 EA 2 Product Documentation
admin.databaseGetId

admin.databaseGetId(
   config as element(configuration),
   database-name as String
) as (Number|String)

Summary

This function returns the ID for the specified database from the configuration. The difference between this function and xdmp:database() is that the ID from this function can come from a database that has not yet been saved (that is, from a database that has been created in the same query with the Admin library but has not yet been saved to the cluster configuration files). This ID enables you to completely configure a newly created database without the need to first save the configuration.

Parameters
config A configuration specification, typically as returned from one of the Admin module functions.
database-name The name of the database.

Required Privileges

This operation requires at least one of the following privileges:

http://marklogic.com/xdmp/privileges/admin/database

http://marklogic.com/xdmp/privileges/admin/database/{id}

Example

  
  const admin = require('/MarkLogic/admin.xqy');
  const config = admin.getConfiguration()
  const config = admin.databaseCreate(config, "myNewDatabase",
                  xdmp.database("Security"), xdmp.database("Schemas"))
  const databaseID = admin.databaseGetId(config, "myNewDatabase")
  const fieldspec = admin.databaseField("myField", fn.true() )
  const config = admin.databaseAddField(config, databaseID, fieldspec)
      admin.databaseAttachForest(config, databaseID,
          xdmp.forest("newForest") )

   //Attaches "newForest" and adds the field, "myField" to the newly created
   //database, "myNewDatabase" 
  

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