2016-11-30 27 views
0

我有一個表:CloudantDB:使用db.get方法沒有ID

id: 001 
name: test 
provider_id:ABC123 

,我嘗試用PROVIDER_ID查詢,並得到一個錯誤信息,但不能與ID:001

db.get("ABC123", function(err, data) { 
    // The rest of your code goes here. For example: 
    console.log("Found id:", data); 
    }); 

請給我你的想法如何成功運行db.get + provider_id

回答

1

你不能使用沒有ID的db.get。但是,您可以使用「查詢」或「視圖」查找要查找的文檔。

使用查詢,您可以使用諸如{「provider_id」:「ABC123」}之類的選擇器來查找包含該提供者標識的文檔。

享有可以使用provider_id作爲密鑰和文件編號或null的值,如:

function (doc) { 
    emit(doc.provider_id, doc._id); 
} 

如果您正在使用null作爲值,你應該使用的include_docs=true選項請求。查看您圖書館的文檔,瞭解如何使用視圖和查詢。

+0

thanks @Rhyshort,對我很有幫助 –

相關問題