DEV Community

Pacharapol Withayasakpunt
Pacharapol Withayasakpunt

Posted on

Have anyone tried CouchDB, and various offline implementations (PouchDB)?

PouchDB is an open-source JavaScript database inspired by Apache CouchDB that is designed to run well within the browser.

PouchDB was created to help web developers build applications that work as well offline as they do online.
It enables applications to store data locally while offline, then synchronize it with CouchDB and compatible servers when the application is back online, keeping the user's data in sync no matter where they next login.

var db = new PouchDB('dbname');

db.put({
  _id: 'dave@gmail.com',
  name: 'David',
  age: 69
});

db.changes().on('change', function() {
  console.log('Ch-Ch-Changes');
});

db.replicate.to('http://example.com/mydb');
Enter fullscreen mode Exit fullscreen mode

The real problem seems to be Indexing and Mango queries (i.e. MongoDB-like). It does support Map-Reduce, but its usage is not recommended.

Also, not sure about performance.

Oldest comments (2)

Collapse
 
terreii profile image
Christopher Astfalk

Hi, PouchDB and CouchDB have been my main databases for the last few years.

Both are fast. PouchDBs Performance depends on the users drive.
There are also two other bottlenecks:

Both queries (mango and map-reduce) update their indexes only when they are queried. But they then only update what did charge. So your first query will be slow. On the other hand: you have fast writes.

PouchDB has to first download all data. This is not a problem if you don’t use its offline capabilities or if it is ok for your users to wait. To work around this I recommend you to use PouchDB over HTTP and once all data you need switch to the local data.

They focus on their sync capability. Which requires you to structure your data differently.
For example tags. Normally you would store tags some where else as the entity that tag and you would link them together. In CouchDB and PouchDB you Store them in the entity.

For the queries: Mango is easier to learn. Map-Reduce is more powerful, but harder to learn, and must eval your map code.

PouchDBs guide is good to start. PouchDB runs in their site (open your console). It works also offline! CouchDBs introduction explains the data layout really good (and a bunch of other things). It is shipped with CouchDB.

Sorry for the long answer.

Collapse
 
lybekk profile image
Christoffer Lybekk

In terms of performance, PouchDB seems to do fairly well for end-user applications.
In offpim.app I tend to keep between 5K-10K documents, and it's blazing fast