Skip to content

Instantly share code, notes, and snippets.

View ableasdale's full-sized avatar

Alex Bleasdale ableasdale

View GitHub Profile
@ableasdale
ableasdale / kb-541-1.xqy
Created April 25, 2018 13:06
MarkLogic: Insert document to create read lock
xdmp:document-insert("/for-read-lock.xml",element root{});
@ableasdale
ableasdale / dupes.sh
Created February 8, 2018 12:21
Duplicate URI messages from ErrorLogs
grep "found in forests" all_dbdupuri_messages.txt | awk -F 'found in forests' '{print $2; print $3}' | cut -d " " -f2-4 | sort -n | uniq -c
@ableasdale
ableasdale / ml-default-http-servers.xqy
Created November 23, 2017 09:45
MarkLogic: Get all HTTP Servers for the Default Group
xquery version "1.0-ml";
(: Note this will only work with Application Servers within the default group - change "Default" on line 8 for other groups if you need to :)
import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy";
declare namespace grp = "http://marklogic.com/xdmp/group";
declare variable $config as element(configuration) := admin:get-configuration();
declare variable $group-id as xs:unsignedLong := admin:group-get-id($config, "Default");
@ableasdale
ableasdale / appserver-status-all.xqy
Created November 23, 2017 09:27
MarkLogic: AppServer status for all groups
xquery version "1.0-ml";
for $host in xdmp:hosts()
for $server in xdmp:group-servers(xdmp:host-group($host))
return xdmp:server-status($host,$server)
@ableasdale
ableasdale / ml-db-config.xqy
Created November 23, 2017 09:15
MarkLogic: Get Database Configurations
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";
declare variable $configurations := admin:database-copy(admin:get-configuration(), xdmp:database("Documents"), "XXXXXXXXXXXXXXX");
for $i in $configurations/db:databases/db:database
where fn:not($i/db:database-name eq "XXXXXXXXXXXXXXX")
@ableasdale
ableasdale / template-insert-example.xqy
Created November 16, 2017 14:11
MarkLogic: Create a simple template to map documents to an SQL view (Article-511)
xquery version "1.0-ml";
import module namespace tde = "http://marklogic.com/xdmp/tde"
at "/MarkLogic/tde.xqy";
let $employees :=
<template xmlns="http://marklogic.com/xdmp/tde">
<context>/Employee</context>
<rows>
<row>
@ableasdale
ableasdale / sample-table-data.js
Created November 16, 2017 13:56
MarkLogic: Using JavaScript to insert multiple documents into a given database (Article-511)
declareUpdate();
xdmp.documentInsert(
"/employee1.json",
{ "Employee": {
"ID": 1,
"FirstName": "John",
"LastName": "Widget",
"Position": "Manager of Human Resources" }}),
xdmp.documentInsert(
"/employee2.json",
@ableasdale
ableasdale / content.xml
Created November 9, 2017 21:57
MarkLogic MLCP: Transforming a source document with a transform module
<Root>
<Batch>
<Documents>
<Document>
<Tag id = "elem1">value1</Tag>
<Tag id = "elem2">value2</Tag>
</Document>
<Document>
<Tag id = "elem1">value1</Tag>
<Tag id = "elem2">value2</Tag>
@ableasdale
ableasdale / remove-cpf.xqy
Created September 14, 2017 12:24
MarkLogic: Remove CPF
xquery version "1.0-ml";
declare namespace trgr = "http://marklogic.com/xdmp/triggers";
declare namespace dom = "http://marklogic.com/cpf/domains";
declare namespace pipelines = "http://marklogic.com/cpf/pipelines";
declare variable $DATABASE as xs:string := "Triggers";
declare variable $OTHER-DOCS as xs:string+ := ("http://marklogic.com/cpf/configuration/configuration.xml", "/cpf/domains.css", "/cpf/pipelines.css");
declare function local:schedule-delete($uris as xs:string+) {
@ableasdale
ableasdale / database-totals-table.xqy
Created September 14, 2017 12:19
MarkLogic: Get Total Docs for all databases and generate an HTML table
xquery version "1.0-ml";
declare function local:get-estimate-for-database-by-id($id as xs:unsignedLong) as xs:unsignedLong {
xdmp:invoke-function(function() { xdmp:estimate(doc()) },
<options xmlns="xdmp:eval">
<database>{$id}</database>
</options>)
(: xdmp:database("Documents") :)
};