简体   繁体   English

如何仅获取文档的最新修订版

[英]How to get only the latest revision of a document

I am new to CouchDb/ektorp. 我是CouchDb / ektorp的新手。 According to the ektorp documentation you can generate couchdb views through an annotation like this: 根据ektorp文档,您可以通过如下注释来生成ouchdb视图:

@View( name = "avg_sofa_size", map = "function(doc) {...}", reduce = "function(doc) {...}")

Is there a way to get only the latest revison of each doc, not by id but another attribute? 有没有办法只获取每个文档的最新版本,而不是通过id而是另一个属性? <-- not java specific <-不是特定于Java

And if possible only get only one doc not by id but another attributefrom that view? 如果可能的话,只能从该视图中仅获取一个文档,而不是通过id而是另一个属性? <-- ektorp/java <-ektorp / java

Thakns Thakns

Is there a way to get only the latest revison of each doc? 有没有办法只获取每个文档的最新版本?

Couch always gives you the latest revision, unless you ask for a particular revision: Couch始终会为您提供最新版本,除非您要求特定版本:

GET http://localhost:5984/mydb/doc-123

Returns latest revision of doc-123 返回doc-123的最新版本

GET http://localhost:5984/mydb/doc-123?rev=946B7D1C

Returns a specific revision of doc-123. 返回doc-123的特定修订版。 (Revisions are kept by couch only for conflict resolution. They are removed during compaction and are not replicated, so you shouldn't necessarily count on them being there) (修订仅保留在沙发上用于解决冲突。在压缩期间将其删除,并且不进行复制,因此您不必指望它们在那里)

And if possible only get only one doc by id from that view 而且,如果可能的话,从该视图中只能通过ID获得一个文档

If you just want to get a document by id, there is no need to use a view. 如果您只想通过id获取文档,则无需使用视图。 Looks like you want to do something like this with ektorp: 看起来您想用ektorp做这样的事情:

Sofa sofa = db.get(Sofa.class, id, rev);

Where Sofa is a java class which extends CouchDbDocument 其中Sofa是扩展CouchDbDocument的Java类

如另一个答案所述,如果您未明确指定修订版本,则将始终获得具有最新修订版本的文档。

Sofa sofa = db.get(Sofa.class, id);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM