MarkLogic JavaScript 问题

MarkLogic JavaScript Issue

尝试在 https://docs.marklogic.com/9.0/guide/entity-services/getting-started#id_75988 认真完成实体服务中的这项练习 直到现在,我一直在严格按照说明进行操作,到目前为止一切顺利。 MarkLogic 服务器版本为 9.0-8.2

当我尝试 运行 位于“查询数据”部分的代码(如下)时:

'use strict';
import jsearch from '/MarkLogic/jsearch.mjs';

// Find all occurences of lastName with the value 'washington' contained
// in an es:instance element. Return just the documents in the results.
const people = jsearch.collections('person-envelopes');
const matches = people.documents()
  .where(cts.elementQuery(
      fn.QName('http://marklogic.com/entity-services', 'instance'),
      cts.elementValueQuery('lastName', 'washington')))
  .map(match => match.document)
  .result();

错误:

[javascript] JS-JAVASCRIPT: import jsearch from ('/MarkLogic/jsearch'); -- Error running JavaScript 
request: SyntaxError: Unexpected token import
Stack Trace
At line 2 column 21:
In import jsearch from ('/MarkLogic/jsearch');

1. 'use strict';
2. import jsearch from ('/MarkLogic/jsearch');
3. // Find all occurences of lastName with the value 'washington' contained
4. // in an es:instance element. Return just the documents in the results.

有人可以建议解决方法或解决方案吗?我花了一段时间试图找到解决方案,但没有任何乐趣。不确定网络浏览器(Brave 浏览器的最新版本)是否是问题的一部分。

也许会取代

import jsearch from '/MarkLogic/jsearch.mjs';

const jsearch = require('/MarkLogic/jsearch.sjs');

?

MarkLogic 10 引入了对 JavaScript 模块 (*.mjs) 的支持,所以看起来这是一个在文档中的版本之间共享的示例,但它不应该。

你猜想改成

const jsearch = require('/MarkLogic/jsearch.sjs');

看起来正确。有关使用 jsearch 的示例,请参阅 https://docs.marklogic.com/9.0/guide/search-dev/javascript#id_48662