[英]CouchDB validation prevents DELETE
為沙發編寫驗證功能:
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");
}
一切都很好,除了我現在不能刪除文檔-驗證不允許我這樣做,因為文檔必須包含title
和id
。
如何檢測正在進行的操作?
該解決方案確實像沙發一樣:
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
字段的新文檔。 如果存在,請在刪除途中記錄文件。 這很有趣,但很奇怪-因此,對於更新檢查,我必須處理修訂版本嗎? 但是從主要方面來說,它是可行的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.