Questions tagged [sjs]

MarkLogic integrates JavaScript as a first-class server-side programming language. You can call a JavaScript program from an App Server, and that program has server-side access to the MarkLogic built-in functions. When you put a JavaScript module under an App Server root with a `sjs` file extension, you can evaluate that module via HTTP from the App Server.

Server-Side JavaScript in MarkLogic

MarkLogic integrates JavaScript as a first-class server-side programming language. You can call a JavaScript program from an App Server, and that program has server-side access to the MarkLogic built-in functions.

MarkLogic Server integrates the Google V8 JavaScript engine (https://code.google.com/p/v8/), a high-performance open source C++ implementation of JavaScript.

This version of V8 offers some of the newer EcmaScript 2015 (formerly known as EcmaScript 6) features. Some EcmaScript 15 features are:

  • Arrow Function
  • Spread Operator and rest Parameters
  • Maps and Sets
  • Classes
  • Constants and Block-Scoped Variables
  • Template Strings
  • Symbols

Programming in Server-Side JavaScript

When you put a JavaScript module under an App Server root with a sjs file extension, you can evaluate that module via HTTP from the App Server. For example, if you have an HTTP App Server with a root /space/appserver, and the port set to 1234, then you can save the following file as /space/appserver/my-js.sjs:

xdmp.setResponseContentType("text/plain");
"hello"

Evaluating this module in a browser pointed to http://localhost:1234/my-js.sjs (or substituting your hostname for localhost if your browser is on a different machine) returns the string hello.

Reference

13 questions
2
votes
2 answers

Implement For Loop in Marklogic Javascript?

I can get all the URIs of the documents in a collection by using below XQuery: for $doc in fn:collection("transform") return xdmp:node-uri($doc) But, when I tried to implement this in a Javascript module in MarkLogic, it is getting only last…
Private
  • 1,661
  • 1
  • 20
  • 51
2
votes
1 answer

MarkLogic 9 Clusters - Restricting to certain fields with SJS

I am trying to implement a simple clustering application with MarkLogic 9 using server side Javascript. I have a pretty complicated custom query builder that is already implemented in JS so I would prefer to do it all in a .sjs file. My problem is…
Alec Daling
  • 348
  • 2
  • 13
1
vote
1 answer

How do I write multiple output files using CoRB?

By default when I run a CoRB job that returns data from the process function that data is streamed into a single file on the CoRB client. I have a problem where I need to write the output to different files, one file per URI that is being…
James
  • 38
  • 5
1
vote
1 answer

how to declare output options in sjs file in marklogic

In XQuery I know the syntax to declare the output options like given below: declare option xdmp:output "method=html"; How can I do the same in an SJS module?
Dixit Singla
  • 2,540
  • 3
  • 24
  • 39
1
vote
1 answer

MarkLogic in-mem-update api overriding previous entry kept in memory

I want to delete multiple nodes from document using a loop and hold the updated doc in memory using in-memory-update api. Below is the code I am using: var mem = require("/MarkLogic/appservices/utils/in-mem-update.xqy"); var myDoc =…
Sukesh
  • 99
  • 5
1
vote
1 answer

xdmp.tidy(html) removes useful Article tags

I'm using Marklogic 8. While using xdmp.tidy() to clean and convert HTML to XHTML, it deletes useful "article" tags. Any fix or options to ignore few tags? Do we have other alternative conversion technique? Things Already…
Pavan Sky
  • 149
  • 1
  • 1
  • 13
1
vote
1 answer

Can't able to view a transform in browser using REST in Marklogic 9?

I tried to install below Server-Side JavaScript using this documentation and saved below as rest-sjs function insertTimestamp(context, params, content) { if (context.inputType.search('json') >= 0) { var result = content.toObject(); if…
Private
  • 1,661
  • 1
  • 20
  • 51
1
vote
1 answer

Marklogic 8 pathRangeQuery with namespace in javascript

I need to build a pathRangeQuery for a path with namespace. This is possible in MarkLogic 9 by using the cts.rangeQuery and building a cts.reference. Ex ML9 : var qname = fn.QName("http://mynamespace.com/example","name"); var elRef =…
Mehdi
  • 67
  • 1
  • 1
  • 9
1
vote
1 answer

Marklogic Server Side Javascript: XDMP-CONFLICTINGUPDATES while using explicit commit

I've been having problems with conflicting updates in Marklogic. I'm aware of the cause, but I don't know how to fix it. I have 1 main (.sjs) file which calls two different (.sjs) files which both update a set of documents. In the main file I use:…
sjoerd999
  • 139
  • 2
  • 12
1
vote
1 answer

MarkLogic - query for documents where a specific json property is not defined

I'm using ML8. I have a bunch of json documents in the database. Some documents have a certain property "summaryData", something like: { ...(other stuff)... summaryData: { count: 100, total: 10000, summaryDate: (date value) …
Roy Tang
  • 5,643
  • 9
  • 44
  • 74
1
vote
1 answer

How to call .sjs file from HTML?

I just started learning programming using MarkLogic. I followed documentation, created "sample.sjs" file like in below. https://docs.marklogic.com/guide/jsref/language#id_71272 xdmp.setResponseContentType("text/plain"); "hello" How should I call…
user8420733
0
votes
1 answer

Understanding Transaction Boundaries in server side JavaScript- Marklogic

I wanted to check the transactional boundaries in Server-Side JavaScript in MarkLogic. So I wrote the below code. I wanted to see the document "/docs/first.json" only within this transaction. Basically, I wanted each statements within a server side…
sharu
  • 71
  • 5
0
votes
0 answers

MarkLogic Sparql insert after clear/drop graph

From Query Console after clear/drop the graph. Trying to insert triples from Java using ResourceManager and SJS. It does not getting inserted, but after few (say 5 min) minutes if we try again using java it gets inserted.
Logesh
  • 45
  • 4