包含修订历史记录的CouchDB视图 [英] CouchDB View that includes revision history

查看:102
本文介绍了包含修订历史记录的CouchDB视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对CouchDB非常陌生。

I am very new to CouchDB. Missing SQL already.

无论如何,我都需要创建一个视图,该视图发出我的文档的一些属性以及所有修订ID。

Anyways, I need to create a view that emits a few attributes of my documents along with all the revision IDs.

类似这样的

function(doc) {
    if (doc.type == 'template') {
        emit(doc.owner, {_id: doc._id, _rev: doc._rev, owner: doc.owner, meta: doc.meta, key: doc.key, revisions_ids: What goes here?});
    }
}

但是我如何告诉它包含所有修订?

But how do I tell it to include all the revisions?

我知道我可以叫
http: //对于每个文档(来自我的应用程序),// localhost:5984 / main / 94c4db9eb51f757ceab86e4a9b00cddf

,但这确实不能很好地扩展。

for each document (from my app), but that really does not scale well.

是否有批量获取版本信息的方法?

Is there a batch way to fetch revision info?

任何帮助将不胜感激!

推荐答案

不是旨在将CouchDB修订为版本控制系统。它们仅用于确保写入一致性。 (并防止并发写入期间需要锁定)

CouchDB revisions are not intended to be a version control system. They are only used for ensuring write consistency. (and preventing the need for locks during concurrent writes)

话虽如此,只有最近 _rev 数字对于任何给定文档都是有用的。不仅如此,数据库压缩还将删除所有旧版本。 (压缩永远不会自动运行,而应该是例行维护的一部分)

That being said, only the most recent _rev number is useful for any given doc. Not only that, but a database compaction will delete all the old revisions as well. (a compaction is never run automatically, but is should be part of routine maintenance)

您可能已经注意到,您的视图输出最新的值中的> _rev 号。另外,如果您使用的是 include_docs = true ,则 _rev 号> doc 您的视图结果的一部分。

As you may have already noticed, your view outputs the most recent _rev number in the value of your view output. Also, if you are using include_docs=true, then the _rev number is also shown in the doc portion of your view result.

使用CouchDB作为修订历史记录的策略确实存在,但它们通常很复杂,通常不建议使用。 (查看此问题此博客文章了解有关该主题的更多信息)

Strategies do exist for using CouchDB for revision history, but they are generally complicated, and not usually recommended. (check out this question and this blogpost for more information on that subject)

这篇关于包含修订历史记录的CouchDB视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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