gpt4 book ai didi

javascript - CouchDB 验证可防止 DELETE

转载 作者:行者123 更新时间:2023-11-28 18:52:41 26 4
gpt4 key购买 nike

为沙发编写验证函数:

function(newDoc, oldDoc, userCtx) { 
function isNullOrWhiteSpace(str){ return str === null || str.match(/^\s*$/) !== null; }
function require(field, message) {
message = message || "Document must have a " + field;
if ((!newDoc[field]) || isNullOrWhiteSpace(newDoc[field])) throw({forbidden : message});
};
require("title");
require("content");
}

一切都很好,只是我现在无法删除文档 - 验证不允许我这样做,说文档必须包含 titleid

如何检测现在正在进行哪个操作?

最佳答案

解决方案确实像沙发一样:

function(newDoc, oldDoc, userCtx) { 
function isNullOrWhiteSpace(str){ return str === null || str.match(/^\s*$/) !== null; }
function require(field, message) {
message = message || "Document must have a " + field;
if ((!newDoc[field]) || isNullOrWhiteSpace(newDoc[field])) throw({forbidden : message});
};

if(!newDoc._deleted){
require("title");
require("content");
}
}

关键点是检查新文档中的 _deleted 字段。如果存在,记录删除过程。这很有趣,但很奇怪——那么,为了进行更新检查,我必须处理修订版本更改吗?但在主要方面,它是有效的。

关于javascript - CouchDB 验证可防止 DELETE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34221859/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com