我是CouchDB的新手,努力實現一個基本示例。我有三個文件客戶,聯繫人,地址,我想將它們合併成一個文件。Couchdb參考文檔
帳戶文件
{
"_id": "CST-1",
"_rev": "8-089da95f148b446bd3b33a3182de709f",
"name": "Customer",
"code": "CST-001",
"contact_Key": "CNT-001",
"address_Key": "ADD-001",
"type": "Customer"
}
聯繫文檔
{
"_id": "CNT-001",
"_rev": "8-079da95f148b446bd3b33a3182de709g",
"fullname": "Happy Swan",
"type": "Contact"
}
地址文件
{
"_id": "ADD-001",
"_rev": "8-179da95f148b446bd3b33a3182de709c",
"street1": "9 Glass View",
"street2": "Street 2",
"city": "USA",
"type": "Address"
}
地圖/查詢:
var map= function (doc) {
if (doc.type === 'Customer') {
emit(doc.id, { contact_Key: doc.contact_Key, address_Key: doc.address_Key })
}
};
db.query({ map: map }, { include_docs: true }, function (err, res) {
});
當我查詢帳戶時,我希望在單個文檔中記錄所有3個文檔。
預期的結果
{
"_id": "CST-1",
"_rev": "8-089da95f148b446bd3b33a3182de709f",
"name": "Customer",
"code": "CST-001",
"contact_Key": "CNT-001",
"address_Key": "ADD-001",
"type": "Customer",
"Contact: {
"_id": "CNT-001",
"_rev": "8-079da95f148b446bd3b33a3182de709g",
"fullname": "Happy Swan",
"type": "Contact"
}",
"Address: {
"_id": "ADD-001",
"_rev": "8-179da95f148b446bd3b33a3182de709c",
"street1": "9 Glass View",
"street2": "Street 2",
"city": "USA",
"type": "Address"
}"
}
你嘗試加入所有3裏面的文件/ reduce?什麼鏈接文檔? 'contact_Key'和Contact的'_id'不匹配。另外,您的「地圖」功能只能發送客戶文件。 – TheDude
嗨,老兄我已經修好了ID,是的,我想加入然後內部馬爾/減少,但不知道如何得到結果。 – yaadgar