CouchDB是否支持引用完整性? [英] Does CouchDB supports referential integrity?

查看:101
本文介绍了CouchDB是否支持引用完整性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是CouchDB的新手,正在学习它。我没有遇到CouchDB对引用完整性的支持。
我们可以为CouchDB文档中的字段创建外键吗?

I am new to CouchDB and learning about it. I did not come across CouchDB support for referential integrity. Can we create a foreign key for a field in the CouchDB document?

例如是否可以确保在订单文档中使用的供应商名称在供应商数据库中可用?

For e.g. Is it possible to ensure a vendor name used in a order document is available in the vendor database?

CouchDB是否支持参照完整性?
并且可以在文档中将字段作为主键吗?

Does CouchDB support referential integrity? And Is it possible to make a field in a document as Primary key?

推荐答案

不,CouchDB不能这样执行外键,因此您不能让它为您处理系统的参照完整性。您需要在应用程序级别检查供应商。

No, CouchDB doesn't do foreign keys as such, so you can't have it handle the referential integrity of the system for you. You would need to handle checking for vendors in the application level.

关于是否可以将字段设为主键,主键是_id字段,但是您可以可以使用任何有效的json作为数据库视图的键。因此,例如,您可以使用卖方作为关键字来创建订单视图。

As to whether you can make a field a primary key, the primary key is the _id field, but you can use any valid json as a key for the views on the db. So, for instance you could create a view of orders with their vendor as the key.

类似

function(doc) {
  if (doc.type == 'order')
    emit(doc.vendor,doc);
}

将在数据库中获取所有具有type属性且值为value的文档并使用供应商作为关键字将其添加到视图中。

would grab all the docs in the database that have a type attribute with the value order and add them to a view using their vendor as the key.

CouchDB视图简介

这篇关于CouchDB是否支持引用完整性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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