在MarkLogic中搜索文档属性的节点代码

问题描述:

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中搜索文档属性的节点代码

+0

您可以使用两个非常小的文档再现案例,并与我们分享? – grtjn

你缺少一个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); 
    }); 
    }); 

而且我可能会建议您按以下格式使用一个承诺的决心处理模式,并允许捕获错误,以及:

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); 
});