【问题标题】:node code to search properties of a document in MarkLogic在 MarkLogic 中搜索文档属性的节点代码
【发布时间】:2017-09-23 05:27:52
【问题描述】:
var marklogic=require('marklogic');
var ins=marklogic.createDatabaseClient({'host':'localhost','port':'7010','user':'admin','password':'admin',});
var qb=marklogic.queryBuilder;
ins.documents.query(
  qb.propertiesFragment(
    qb.value("Author","Akhilesh Sabbisetti"))
  ).result(function(matches){
    matches.forEach(function(match){
      console.log(match.uri);
    });
  });

上面的代码应该只适用于文档的属性,但它不是那样工作的。我得到了不相关的结果。请更正我的代码....

【问题讨论】:

  • 你能用两个非常小的文件复制这个案例,并与我们分享吗?

标签: marklogic marklogic-9


【解决方案1】:

您缺少qb.where() 方法:

var marklogic=require('marklogic');
var ins=marklogic.createDatabaseClient({'host':'localhost','port':'7010','user':'admin','password':'admin',});
var qb=marklogic.queryBuilder;
ins.documents.query(
qb.where(
  qb.propertiesFragment(
    qb.value("Author","Akhilesh Sabbisetti"))
  )
).result(function(matches){
    matches.forEach(function(match){
      console.log(match.uri);
    });
  });

我还可以建议您使用以下格式的 promise resolve 处理模式,并允许捕获错误:

db.documents.query(
  qb.where(
    qb.propertiesFragment(
      qb.value('Author', 'Akhilesh Sabbisetti')
    )
  )
)
.result()
.then(function(matches) {
  console.log(matches);
})
.catch(function(error) {
  console.log(error);
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-25
    • 1970-01-01
    相关资源
    最近更新 更多