0

我试图找到一种方法来确保某些内容存在于 CouchDB 数据库的文档中。我认为最好的方法是使用“validate_doc_update”设计文档。过去我创建了一个检查用户是否有权对数据库进行更改的程序,因此我尝试在其中包含此附加代码。但是,它在 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.'});
}

}

4

1 回答 1

0

不匹配的大括号是问题的原因。如果有任何更有效/“正确”的方法来做我想做的事情(没有像我即将做的那样将 if 语句压缩成一个 IF 语句),我将非常感谢这些信息。

于 2016-02-16T10:40:24.647 回答