marklogic - 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 10 引入了对 JavaScript 模块 (*.mjs) 的支持,因此看起来这是一个在文档中的版本之间共享的示例,但不应该如此。
您的猜测将其更改为
const jsearch = require('/MarkLogic/jsearch.sjs');
看起来正确。有关使用 jsearch 的示例,请参阅https://docs.marklogic.com/9.0/guide/search-dev/javascript#id_48662。
推荐阅读
- android - 发送带有改造的 utf8 字符作为查询参数
- python - Python Turtle 在打开第二个窗口时崩溃
- amazon-web-services - 如何让 traefik 在我的云架构上工作?
- android - 如何以编程方式将字符串添加到资源值?
- java - 在android中比较两个字符串,如url
- netlogo - Netlogo:计算自己和其他代理之间的距离
- google-apps-script - 试图从工作表中的不同选项卡获取 url
- jquery - 在移动设备上强制 jPlayer 缓冲条
- c# - PHP的openssl_sign在C#中使用字符串
- vb.net - InternetMessageHeaders 不更新 EWS