尝试在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();it错误:
[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.有没有人能给我一个建议或者解决方案?我花了一段时间试图找到解决方案,但没有任何乐趣。不确定web浏览器(最新版本的Brave浏览器)是否是问题的一部分。
可能会替换掉
import jsearch from '/MarkLogic/jsearch.mjs';使用
const jsearch = require('/MarkLogic/jsearch.sjs');发布于 2021-01-15 18:21:59
MarkLogic 10引入了对JavaScript模块(*.mjs)的支持,所以看起来这是一个在文档版本之间共享的示例,但它不应该是这样的。
您的猜测是将其更改为
const jsearch = require('/MarkLogic/jsearch.sjs');看起来没问题。有关使用jsearch的示例,请参阅https://docs.marklogic.com/9.0/guide/search-dev/javascript#id_48662。
https://stackoverflow.com/questions/65730905
复制相似问题