简体   繁体   中英

How to get only the latest revision of a document

I am new to CouchDb/ektorp. According to the ektorp documentation you can generate couchdb views through an annotation like this:

@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? <-- not java specific

And if possible only get only one doc not by id but another attributefrom that view? <-- ektorp/java

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:

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

Returns latest revision of doc-123

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

Returns a specific revision of 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

If you just want to get a document by id, there is no need to use a view. Looks like you want to do something like this with ektorp:

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

Where Sofa is a java class which extends CouchDbDocument

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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