Is there a method to retrieve all versions of a file in PouchDB while utilizing the change feed feature?

Currently experimenting with PouchDB, I am using it for local data storage without any connection to CouchDB. My goal is to develop a method for reverting or undoing changes to a single document by utilizing its previous revisions. While browsing through the PouchDB documentation, I stumbled upon the changes feed which initially appeared to be a way to retrieve all revisions of every document. However, my attempts at fetching all revisions only resulted in obtaining the latest revision. I tried the following code snippet to fetch the changes:

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

In summary, how can I access all revisions of one or more documents in PouchDB?

Answer №1

Thanks to the assistance of macrog, I have successfully discovered a solution to achieve my desired outcome. In essence, I wanted to retrieve all revisions of my documents, even those that had been deleted. Here is the code snippet that now accomplishes this:

db.get(String(id), {
    revs: true, 
    open_revs: 'all' // by setting this parameter, I can also access removed "docs"
  }).then(function(found) {
    console.log(found);
  });

Although I have discontinued using db.changes() for retrieving all document revisions, I am pleased that I am now able to accomplish my initial goal.

Answer №2

Consider trying one of the alternatives mentioned in the pouchdb documentation:

Use db.get(docId, [options], [callback]) to retrieve a document specified by docId.

Here are some available options:

options.rev: Fetch a specific revision of a document (defaults to winning revision).

options.revs: Include the revision history of the document.

options.revs_info: Get a list of revisions of the document and their availability.

options.open_revs: Retrieve all leaf revisions if open_revs="all" or fetch specified leaf revisions in the same order as listed in the input array.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having trouble with a blank page when starting up a basic Angular SPA in ASP .NET 5?

Currently, I am in the process of setting up a basic Angular single-page-application within ASP .NET 5. The project starts with a clean slate, with only the ngRoute Angular dependency included. The issue at hand: Upon running the project, I am faced wi ...

Prevent dragging within a sortable bootstrap element with a map embedded

I am facing an issue with elements managed by Bootstrap sortable plugins (x_panels). Within one of these panels, there is a map element that can be dragged. However, when I try to drag the map, it activates the sortable start event and moves the entire pan ...

Why is the Twitch api map function returning nothing, while the console log is showing output?

Presently, my Nextjs page is making multiple Twitch API calls successfully and displaying the correct data. However, one of the mapping functions is failing to render anything on the page, even though the console log shows the data. Although I am relativel ...

Tips for transforming an Observable stream into an Observable Array

My goal is to fetch a list of dogs from a database and return it as an Observable<Dog[]>. However, whenever I attempt to convert the incoming stream to an array by using toArray() or any other method, no data is returned when calling the retrieveDo ...

Switching from using jQuery's $.ajax method to Angular's $http service

I have been working on a jQuery code snippet that works seamlessly across different origins: jQuery.ajax({ url: "http://example.appspot.com/rest/app", type: "POST", data: JSON.stringify({"foo":"bar"}), dataType: "json", contentType: "a ...

Ways to organize a directory structure of folders

I am working with a tree structure of folders that have properties such as id, parent_id, and name. Currently, this tree is stored in an unsorted array. Each element in my array looks like this: var obj = { id: 1, parent_id: null, name: "Folder" } My go ...

Chrome is blocking the loading of a local image in THREE.js due to cross-origin restrictions

While working with THREE.js, I encountered an issue in the developer console: Cross-origin image load denied by Cross-Origin Resource Sharing policy. This error only occurs when I try to run my script in Chrome. The code snippet in question is as follows ...

The DOMException occurred when attempting to run the 'querySelector' function on the 'Document' object

Currently, I am engaged in a project that was initiated with bootstrap version 4.3.1. I have a keen interest in both JavaScript and HTML coding. <a class="dropdown-item" href="{{ route('user.panel') }}"> User panel </a& ...

Eradicate HTML by assigning empty values to certain attributes

Allowing the user to copy the HTML code of a div by clicking a button. Some attributes, such as for videos: <video loop muted autoplay> may appear like this after copying: <video loop="" muted="" autoplay=""> The ...

Managing the output from a function: Tips and strategies

Below is the function I am currently working with: function kontrola(){ var jmeno = self.document.forms.newPassForm.user.value; $.get("checkMail.php?mail="+jmeno, function(data){ if(data=='1'){ alert('Tento ...

Getting the value from a text box in a form using JavaScript, appending it to a predetermined string, and redirecting the browser to display the resulting value

Can anyone help me with a simple code request? Here is what I need: Request the user to enter a value in a text box (e.g. '12345'). Take the entered value and add it to a default URL string (e.g. ''). Update the browser's URL to ...

Encountering deployment error with PM2 and Meteor collaboration

I have implemented the "pm2-meteor" module to integrate PM2 into my Meteor Application. [Using PM2 for the First Time] I referred to the documentation provided in pm2-meteor, which can be found at: https://www.npmjs.com/package/pm2-meteor After follo ...

Error: Vue is unable to access the property '_modulesNamespaceMap' because it is undefined

I've been working on a simple web app to enhance my testing skills in Vue using Vue Test Utils and Jest. However, I encountered an error related to Vue while trying to console log and check if AddDialog is present in my Home file. The error message I ...

angular ignoring selected option

Upon examining the HTML code below, there is an issue with selecting an option based on the sport.slug: <div class="form-group" ng-hide="controller.sports.loading"> <label for="sport">Sport</label> <div class="input-group"> ...

Ways to retrieve the __proto__ property within NodeJS?

After declaring an array as var arr = [] in the browser console, I noticed that doing arr.__proto__ displays the prototype in the console. Browser Javascript However, when attempting the same action in NodeJs, the result is simply []. NodeJs Given that ...

Error thrown when executing an Angular query

I've been working on developing a basic app that allows users to search for contacts and view individual items. However, I encountered an error when trying to access a single item. I attempted using 'get' instead, but it caused issues with o ...

Guide to altering the color of the row that is clicked in a table using css and jquery

Is there a way to change the text color of a row in a table when it is clicked, similar to an example like this but without changing the background color? The code I have tried is not working for me. Below is a snippet of the code I am using: $("#myTab ...

Is there a way to trigger a Tab key click event while typing in a text field?

Can you show me how to capture the Tab key event in jQuery? I want to display an alert if a user clicks the Tab key while entering text in an input field. I have tried using the following code but it's not working... var myInput = document.getEleme ...

fetch information using ajax and jquery

I'm facing an issue with my ajax request on my website. I'm trying to dynamically fetch pages from a database using jquery and ajax. However, I'm not getting any response, and I'm unsure whether the problem lies in my php code or my j ...

Is it possible to include an argument in an unnamed function in Node.js without assigning it to a variable?

Coming from a C/C++ background, I've been struggling with grasping the syntax of node.js. After searching online for code examples to explain blocking and non-blocking operations, I stumbled upon a piece that has left me perplexed for hours. Despite m ...