akh*_*tti 2 marklogic marklogic-9
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);
});
});
Run Code Online (Sandbox Code Playgroud)
上面的代码应该只适用于文档的属性,但它不是那样的.我得到了无关紧要的结果.请更正我的代码....
你错过了一个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);
});
});
Run Code Online (Sandbox Code Playgroud)
我还建议您使用以下格式的promise解决处理模式,并允许捕获错误:
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);
});
Run Code Online (Sandbox Code Playgroud)