【问题标题】:MarkLogic JavaScript IssueMarkLogic JavaScript 问题
【发布时间】:2021-01-15 05:22:34
【问题描述】:

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


    【解决方案1】:

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

    您的猜测将其更改为

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

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

    【讨论】:

    • 好的,谢谢。这个问题来自于一个在数据中心内构建简单实体模型的示例。请问是否有其他工作示例(在 MarkLogic 培训课程之外)涵盖在数据中心内构建简单的实体模型?在寻求进一步指导之前,我喜欢通过自己尝试和解决问题。
    猜你喜欢
    • 2016-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多