使用更改提要时,是否有办法在PouchDB中获取文档的所有修订版本? [英] Is there a way to get all revisions of a document in PouchDB when using the change feed?

查看:90
本文介绍了使用更改提要时,是否有办法在PouchDB中获取文档的所有修订版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此刻,我正在摆弄PouchDB。我将其用作在本地存储数据而不将其链接到CouchDB的一种方式。我一直在尝试为单个文档创建一个还原/撤消方法。为此,我想使用 doc的先前版本。在阅读PouchDB文档时,我遇到了更改提要,这乍一看似乎是获得所有文档的所有修订的一种方式。但是,在尝试获取文档的所有修订后,我仅获得了最新修订。我尝试了以下操作来进行更改:

I'm fiddling around with PouchDB at the moment. I use it as a way to store data locally without it being linked to CouchDB. What I've been trying to do is to create a revert/undo method for a single doc. For this I would like to use the previous revisions of the "doc". I came across the changes feed while reading the PouchDB documentation, which at first seems to be a way to get all the revisions of the all the "docs". However, after trying to get all the revisions of the "docs" I've only got the latest revision. I've tried the following to get the changes:

db.changes({
    since: 0,
    style: 'all_docs',
    include_docs: true // eslint-disable-line camelcase
  }).then(function(results) {
    console.log(results);
  }); 

TL; DR如何获取(一个或多个)文档的所有修订PouchDB?

TL;DR how can I get all the revisions of a (or all) document(s) in PouchDB?

推荐答案

macrog 我找到了一种可以做自己想做的方法。简短摘要我想要一种方法来获取我的文档的所有修订版,包括已删除的文档。这就是我现在使用的:

With some help of macrog I've found a way to do what I wanted to do. Short summary I wanted a way to get all revisions of my documents, including the ones which had been removed. This is what I use now:

db.get(String(id), {
    revs: true, 
    open_revs: 'all' // this allows me to also get the removed "docs"
  }).then(function(found) {
    console.log(found);
  });

我没有日志记录器,请使用db.changes()获取文档的所有修订版。但至少我能做我想做的事。

Granted I no loger use db.changes() to get all the revisions of a document. But at least I'm able to do what I wanted to do.

这篇关于使用更改提要时,是否有办法在PouchDB中获取文档的所有修订版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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