首页 > 解决方案 > MarkLogic JavaScript 问题

问题描述

尝试在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

解决方案


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

您的猜测将其更改为

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

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


推荐阅读