Reputation: 2137
I adapted the code below from some XQuery. However, when I run it, it only inserts the document into collection B
, not collections A
and B
as the equivalent XQuery does.
declareUpdate();
xdmp.documentInsert(
'mydoc.xml',
fn.head(xdmp.unquote(`<mydoc/>`)),
xdmp.defaultPermissions(),
('A', 'B')
);
Upvotes: 2
Views: 113
Reputation: 2137
The problem is the ('A', 'B')
. In XQuery that represents a sequence of two strings. In JavaScript, that’s interpreted as two statements and returns the result of the last one, in this case 'B'
. Thus the syntax is valid—which is why there’s no error—but the intent is different. In general, the equivalent of an XQuery sequence in JavaScript is an array. Thus the code above should be
declareUpdate();
xdmp.documentInsert(
'mydoc.xml',
fn.head(xdmp.unquote(`<mydoc/>`)),
xdmp.defaultPermissions(),
['A', 'B']
);
Note the square brackets on ['A', 'B']
. This is something to watch out for when copy-pasting from XQuery to JavaScript.
Upvotes: 3