Skip to content

Instantly share code, notes, and snippets.

View prestonmcgowan's full-sized avatar

Preston McGowan prestonmcgowan

View GitHub Profile
'use strict';
const APP_SERVER_TO_DELETE = 'myApp';
const admin = require('/MarkLogic/admin.xqy');
let config = admin.getConfiguration();
const groupId = fn.head(admin.getGroupIds(config)); // ASSUMPTION: only one group
'use strict';
// Set this to the output of app-server-components.sjs
const itemsToDelete = {"group":{"name":"Default", "id":"9058960804898839955"}, "appServer":{"name":"myApp", "id":"9351623035930725670"}, "contentDatabase":{"name":"myApp-content", "id":"743264865753505898", "forests":[{"name":"myApp-content-1", "id":"5044318450693390831"}, {"name":"myApp-content-2", "id":"12748819722917748087"}, {"name":"myApp-content-3", "id":"7007370367638532332"}]}, "modulesDatabase":{"name":null, "id":null, "forests":null}, "schemasDatabase":{"name":null, "id":null, "forests":null}, "triggersDatabase":{"name":null, "id":null, "forests":null}};
// Keep hitting "run" until you see "All Done"
const admin = require('/MarkLogic/admin.xqy');
let config = admin.getConfiguration();
xquery version "1.0-ml";
import module namespace sec="http://marklogic.com/xdmp/security" at "/MarkLogic/security.xqy";
declare function local:get-role-names($role-ids) {
xdmp:invoke-function(
function() {
sec:get-role-names($role-ids)
},
<options xmlns="xdmp:eval">
@prestonmcgowan
prestonmcgowan / tasks.json
Last active May 22, 2019 20:53
Visual Studio Code: Gradle Tasks
{
"_comment": [
"See https://go.microsoft.com/fwlink/?LinkId=733558",
"for the documentation about the tasks.json format"
],
"version": "2.0.0",
"tasks": [
{
"label": "mlDeploy",
"type": "shell",
xquery version "1.0-ml";
(: Configurable variables :)
declare variable $initial-radius := 1; (: miles :)
declare variable $radius-step := 5; (: miles :)
declare variable $radius-max := 100; (: miles :)
declare variable $total-matches := 1;
declare variable $lat-long-element-container := "FacilitySite";
declare variable $lat-element := "LatitudeMeasure";
// Use VSCode with mlxprs or MarkLogic Query Console
let tdeDirectory = cts.uriMatch("/tde/*.tdex").toArray();
tdeDirectory.map( u => {
let tdex = cts.doc(u);
return { u, valid: tde.validate([tdex]) };
});
@prestonmcgowan
prestonmcgowan / copy-documents-between-module-databases.xqy
Created October 10, 2019 16:23
Copy documents between two MarkLogic module databases (or any two MarkLogic databases really)
xquery version "1.0-ml";
let $ui-uris := cts:uri-match("/lib/*", "document")
for $u in $ui-uris
return
xdmp:eval('
declare variable $u external;
declare variable $d external;
declare variable $p := ( xdmp:permission("rest-extension-user", "execute"), xdmp:permission("rest-admin", "update"), xdmp:permission("rest-admin", "read"), xdmp:permission("ui-role", "update"), xdmp:permission("ui-role", "read"), xdmp:permission("ui-role", "execute") );
xdmp:document-insert($u, $d, $p)
@prestonmcgowan
prestonmcgowan / decode-binary.xqy
Created October 10, 2019 18:43
Decode a hex binary with XQuery
(:: Decode a hex binary ::)
xquery version "1.0-ml";
xdmp:save(
"D:\save.json",
binary{ xs:hexBinary( fn:doc("/big-json.xml")//hexbin/node() ) }
)
@prestonmcgowan
prestonmcgowan / element-attribute-range-index-report.xqy
Created October 10, 2019 18:44
Report of MarkLogic Element Attribute Range Indexes
xquery version "1.0-ml";
import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy";
declare namespace db ="http://marklogic.com/xdmp/database";
let $constraint := cts:collection-query("content")
let $config := admin:get-configuration()
@prestonmcgowan
prestonmcgowan / element-range-index-report.xqy
Created October 10, 2019 18:45
Report on MarkLogic Element Range Indexes
xquery version "1.0-ml";
import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy";
declare namespace db ="http://marklogic.com/xdmp/database";
let $constraint := cts:collection-query("content")
let $config := admin:get-configuration()