2017-09-23 66 views
1
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

回答

5

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