0
我想找到一種方法來確保某些內容存在於CouchDB數據庫的文檔中。我認爲這樣做的最好方法是使用「validate_doc_update」設計文檔。過去我創建了一個用於檢查用戶是否有權更改數據庫的嘗試,因此我嘗試在其中包含此附加代碼。但是它在CouchDB中不被識別爲可編譯的代碼,我不確定爲什麼(請參閱下面的代碼)。有沒有人知道我已經搞亂了這段代碼,使它不能編譯,或者如果有更好的方法去確保某些字段包含在更新的文檔中?如何確保CouchDB數據庫中包含某些字段?
這包括在同一個數據庫中的設計文檔名爲「_design/BGdesign」:
function(newDoc, oldDoc, userCtx, secObj){
if ('_admin' in userCtx.roles) return; // skip anonymous in Admin Party case
if (userCtx.roles.indexOf('testAdmin') == -1) {
throw({forbidden: "Not Authorized"});
}
}
if (newDoc.artistName === undefined) {
throw({forbidden: 'Document must have a artistName'});
}
if (newDoc.currentLocation === undefined) {
throw({forbidden: 'Document must have a currentLocation'});
}
if (newDoc.dateMade === undefined) {
throw({forbidden: 'Document must have a dateMade.'});
}
if (newDoc.description === undefined) {
throw({forbidden: 'Document must have a description.'});
}
if (newDoc.name === undefined) {
throw({forbidden: 'Document must have a name.'});
}
if (newDoc.owner === undefined) {
throw({forbidden: 'Document must have an owner.'});
}
if (newDoc.tags === undefined) {
throw({forbidden: 'Document must have tags.'});
}
if (newDoc.uploaded === undefined) {
throw({forbidden: 'Document must have an uploaded date.'});
}
}
你似乎有不匹配的花括號。 –
啊,該死的,所以我願意。這樣的菜鳥錯誤。謝謝 :) – GameCrazed