Javatpoint Logo
Javatpoint Logo

PouchDB Interview Question


1) What is PouchDB?

PouchDB is an open-source "in-browser" database API written in JavaScript. It is modeled after CouchDB(a NoSQL database that powers npm). It facilitates you to build applications that work offline and online by using this API. PouchDB uses WebSQL and IndexedDB internally to store the data.

For more information: Click Here


2) How does PouchDB work?

PouchDB stores data locally using WebSQL and IndexedDB in the browser, when the application is offline. When the application back online, the data is synchronized with CouchDB and compatible servers.

PouchDB facilitates you to communicate both local and remote databases seamlessly without facing any difference.


3) What are the most important features of PouchDB?

The most important features of PouchDB are given below:

Cross Browser: PouchDB is cross-browser. The API provided by PouchDB works the same in every environment, so, a PouchDB application can be run in various browsers.

Light Weight: PouchDB is a very light-weight API, it is also included easily just using a script tag.

Easy to Learn: PouchDB is very easy to learn if you have a prior knowledge of any programming language.

Open Source: PouchDB is an Open Source Application which is available on GitHub.


4) Which are the browsers that support PouchDB?

Following are the main browsers that support PouchDB:

  • Firefox 29+ (Including Firefox OS and Firefox for Android)
  • Chrome 30+
  • Safari 5+
  • Internet Explorer 10+
  • Opera 21+
  • Android 4.0+
  • iOS 7.1+
  • Windows Phone 8+

5) What are the advantages of using PouchDB?

Advantages of using PouchDB:

  • PouchDB is extremely fast because it resides within the browser and you don't have any need to perform queries over the network. That's why it is fast.
  • The data with any of the supported server can be synchronized and by doing so we can run apps both online and offline.

6) How to install PouchDB on your system?

There are several ways to install PouchDB on your system but by using Node.js and npm is the easiest and efficient way to install PouchDB.

For more information: Click Here


7) How to create a database in PouchDB?

A database is created very easily in PouchDB by using constructor.

Syntax:

You have to install Node.js and a PouchDB package is required using the require() method to create a database.

Example:

For more information: Click Here


8) What is the use of db.info() method in PouchDB?

The db.info() method is used to get the information about the database. This method also accepts a callback function.

See the given example for retrieving data from the database using the info() method. Here the database name is my_database.

Example:

For more information: Click Here


9) How to delete a database created in PouchDB?

The db.destroy() method is used to destroy a database in PouchDB.


10) How to use db.destroy() method with Node.js to delete a database?

Following is the syntax of using the db.destroy() method. It also accepts a callback function.

Syntax:

See the following example how to use db.destroy() method.

Example:

For more information: Click Here


11) How to delete a remote database that is stored on a remotely server CouchDB?

Provide the path of the remotely database CouchDB in PouchDB constructor to delete a database that is stored on a remotely server CouchDB.

For example:

For more information: Click Here


12) What is the use of db.put() method in PouchDB?

The db.put() method is used to create documents in PouchDB databases.

Syntax:

This method also supports callback function.

For more information: Click Here


13) How can you fetch the created document in PouchDB database?

The db.get() method is used to retrieve the documents created in PouchDB database. This method accepts the document id and an optional callback function.

Syntax:

For more information: Click Here


14) How can you update an existing document in PouchDB database?

Every time you create a document, a new field _rev is get generated. It is called revision marker. The _rev's value is a unique random number, which is changed every time we make changes to the document.

The db.put() method is used along with _rev value to update a document.

For more information: Click Here


15) How can you delete a document in PouchDB?

The db.remove() method is used to delete the document created in PouchDB database. In this method, id and _rev are to be passed to delete an existing document as shown in the following code. This method accepts an optional callback function. The complete document can also be passed instead of id and _rev.

Syntax:

For more information: Click Here


16) What is Batch? How to create a batch in PouchDB?

Batch is an array of documents in PouchDB. When you use this method to create documents, it creates unique ids for all the documents in bulk if you not specifies the _id values.

All the documents you have created in PouchDB can be stored in an array and can be passed as a parameter in this method. This method also accepts callback functions as a parameter.

Syntax:

To know how to create a batch, see the following link:

For more information: Click Here


17) How to fetch the created batch in PouchDB database?

The allDocs() method is used to featch the multiple/bulk documents from the database. This method also accepts an optional callback function.

Syntax:

For more information: Click Here


18) How to update an already created Batch in PouchDB database?

The bulkDocs() method is used to update an array of documents in PouchDB. To update a value of batch, you have to know the _id, _rev and the values that you want to update.

For more information: Click Here


19) How would you delete a batch in PouchDB?

The bulkDocs() method is used also for deleting an array of documents. To delete a batch, you have to know the _id and _rev values of the documents.

For more information: Click Here


20) What is an attachment in PouchDB?

In PouchDB, an attachment is a binary object that can be attached to a document.


21) How can you add an attachent to a document in PouchDB?

The putAttachment() method is used to add an attachment to a document in PouchDB. You have to pass the document id, attachment id, MIME type along with the attachment. This method also accepts an optional callback function.

Syntax:

For more information: Click Here


22) How can you retrieve a PouchDB added attachment?

The getAttachment() method is used to retrieve an attachment from the PouchDB document. This method always returns blob or buffer objects. You have to pass the document id and attachment id to use this method. This method also accepts an optional callback function.

Syntax:

For more information: Click Here


23) How can you delete a PouchDB added attachment?

The removeAttachment() method is used to delete an attachment from PouchDB document. To use this method, you have to pass the document id, attachment id, and _rev value. This method also accepts an optional callback function.

Syntax:

For more information: Click Here