根据现有文档中的内容进行ouchdb验证 [英] couchdb validation based on content from existing documents

查看:46
本文介绍了根据现有文档中的内容进行ouchdb验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题

是否可以作为标准beddb验证功能的一部分查询其他beddb文档?

Is it possible to query other couchdb documents as part of a standard couchdb validation function ?

如果没有,那么将其他文档的属性作为验证规则的一部分包含在Sofadb验证函数中的标准方法是什么?

If not, what is the standard approach for including properties of other documents as part of a validation rule inside a couchdb validation function?

RATIONALE

考虑一个普通的地址簿应用程序,其中的验证功能旨在防止两个或多个具有相同值的条目

Consider a run-of-the-mill address book application where the validation function is intended to prevent two or more entries having the same value for the 'e-mail' in one of the address book entry fields.

还要考虑一个通讯簿应用程序,可以在单独的文档中指定验证规则,基于

Consider also an address book application where it is possible to specify validation rules in separate documents, based on whether the postal code is a US-based postal code or something else.

推荐答案

否,无法查询其他在 validate_doc_update 函数中的ouchdb文档。每个文件都是独立运行的,仅引用以下内容:新文档,旧文档和用户(如果适用)。

No, it is not possible to query other couchdb documents in a validate_doc_update function. Each runs in isolation passing references only to: the new document, the old document, and user (where applicable).

我的个人经历至少有三个选择处理重复检查的地方:

My personal experience has been there are at least three options for dealing with duplicate checking:


  1. 使用Cloudant作为您的CouchDB提供程序。如果您想尝试,它们现在提供免费层,但是它们保证了CouchDB数据库的各个节点之间的一致性。 (请参阅#2)

  2. 我使用了第二个保留表来存储使用类型键作为ID的名称。然后,如果不使用Cloudant之类的系统,则需要检查是否存在冲突。基本上,有一个简单的文档,其中包含防止重复的密钥。考虑到您需要注意冲突,编写这段代码并不有趣。 (即使使用cloudant,您也需要处理失败的写入请求,但是比处理围绕多个节点的数据复制的时序问题要容易得多。)

  3. 使用像MySQL这样的传统数据库可以为您描述的特定数据值保持唯一且一致的索引。但是,将文档存储在CouchDB中。尽管有点烦人,您需要其他数据提供者,但它是可靠的。

  4. (可选:确定CouchDB不适合您要构建的系统类型)

  1. Use Cloudant as your CouchDB provider. They offer a free tier for now if you'd like to experiment, but they guarantee consistency across nodes for a CouchDB database. (See #2)
  2. I've used a secondary "reserve table" for names using the type-key as the ID. Then, you need to check for conflicts if not using a system like Cloudant. Basically, there's a simple document that maintains a key to prevent duplicates. It's not fun code to write given that you need to watch for conflicts. (Even with cloudant, you need to deal with failed requests to write, but it's easier than dealing with timing issues surrounding data replication across multiple nodes).
  3. Use a traditional DB like MySQL for example that can maintain a unique and consistent index for specific data values like you're describing. Store the documents away in CouchDB though. While slightly annoying that you need different data providers, it's reliable.
  4. (Optional: decide that CouchDB isn't a great fit for the type of system you're building)

这篇关于根据现有文档中的内容进行ouchdb验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆